添加导入加密插件"laoqianjunzi-crypto"
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
import type { CryptoBlockMode, CryptoByteCipherOptions, CryptoDesOptions, CryptoPaddingKind, CryptoRuntimeSnapshot, CryptoTextCipherOptions, CryptoTripleDesOptions, RsaOutputKind } from "../interface.uts"
|
||||
|
||||
export function createDefaultTextCipherOptions() : CryptoTextCipherOptions {
|
||||
return {
|
||||
mode: "CBC",
|
||||
padding: "PKCS7",
|
||||
ivText: "0123456789abcdef",
|
||||
keyLength: 16
|
||||
} as CryptoTextCipherOptions
|
||||
}
|
||||
|
||||
export function createDefaultByteCipherOptions() : CryptoByteCipherOptions {
|
||||
return {
|
||||
mode: "CBC",
|
||||
padding: "PKCS7",
|
||||
ivBytes: new Uint8Array([48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 97, 98, 99, 100, 101, 102]),
|
||||
keyLength: 16
|
||||
} as CryptoByteCipherOptions
|
||||
}
|
||||
|
||||
export function createDefaultTripleDesOptions() : CryptoTripleDesOptions {
|
||||
return {
|
||||
mode: "CBC",
|
||||
ivText: "12345678"
|
||||
} as CryptoTripleDesOptions
|
||||
}
|
||||
|
||||
export function createDefaultDesOptions() : CryptoDesOptions {
|
||||
return {
|
||||
mode: "CBC",
|
||||
padding: "PKCS7",
|
||||
ivText: "12345678"
|
||||
} as CryptoDesOptions
|
||||
}
|
||||
|
||||
export function normalizeTextCipherOptions(options : CryptoTextCipherOptions | null) : CryptoTextCipherOptions {
|
||||
if (options == null) {
|
||||
return createDefaultTextCipherOptions()
|
||||
}
|
||||
return {
|
||||
mode: options.mode,
|
||||
padding: options.padding,
|
||||
ivText: options.ivText,
|
||||
keyLength: options.keyLength
|
||||
} as CryptoTextCipherOptions
|
||||
}
|
||||
|
||||
export function normalizeByteCipherOptions(options : CryptoByteCipherOptions | null) : CryptoByteCipherOptions {
|
||||
if (options == null) {
|
||||
return createDefaultByteCipherOptions()
|
||||
}
|
||||
return {
|
||||
mode: options.mode,
|
||||
padding: options.padding,
|
||||
ivBytes: options.ivBytes,
|
||||
keyLength: options.keyLength
|
||||
} as CryptoByteCipherOptions
|
||||
}
|
||||
|
||||
export function normalizeTripleDesOptions(options : CryptoTripleDesOptions | null) : CryptoTripleDesOptions {
|
||||
if (options == null) {
|
||||
return createDefaultTripleDesOptions()
|
||||
}
|
||||
return {
|
||||
mode: options.mode,
|
||||
ivText: options.ivText
|
||||
} as CryptoTripleDesOptions
|
||||
}
|
||||
|
||||
export function normalizeDesOptions(options : CryptoDesOptions | null) : CryptoDesOptions {
|
||||
if (options == null) {
|
||||
return createDefaultDesOptions()
|
||||
}
|
||||
return {
|
||||
mode: options.mode,
|
||||
padding: options.padding,
|
||||
ivText: options.ivText
|
||||
} as CryptoDesOptions
|
||||
}
|
||||
|
||||
export function buildRuntimeSnapshot(platformName : string, engineName : string, supportsAdvancedModes : boolean, usesNativeBridge : boolean) : CryptoRuntimeSnapshot {
|
||||
return {
|
||||
platformName: platformName,
|
||||
engineName: engineName,
|
||||
supportsAdvancedModes: supportsAdvancedModes,
|
||||
usesNativeBridge: usesNativeBridge
|
||||
} as CryptoRuntimeSnapshot
|
||||
}
|
||||
|
||||
export function resolveHexOutput(outputKind : RsaOutputKind | null) : boolean {
|
||||
return outputKind == "hex"
|
||||
}
|
||||
|
||||
export function createAsciiBlock(text : string, size : number) : Uint8Array {
|
||||
const output = new Uint8Array(size)
|
||||
let index = 0
|
||||
while (index < size) {
|
||||
if (index < text.length) {
|
||||
output[index] = text.charCodeAt(index) & 0xff
|
||||
} else {
|
||||
output[index] = 0
|
||||
}
|
||||
index += 1
|
||||
}
|
||||
return output
|
||||
}
|
||||
Reference in New Issue
Block a user