42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import CryptoJS from 'crypto-js';
|
|
|
|
import { ByteUtils } from './ByteUtils';
|
|
import { CipherKeyDTD } from '../models/CipherKeyDTD';
|
|
|
|
export class CipherUtil {
|
|
static makeCipherKey(pvAlgorithm: string, pvUserKey: string): CipherKeyDTD {
|
|
let keyBytes: Uint8Array;
|
|
let ivBytes: Uint8Array;
|
|
|
|
if (
|
|
!pvUserKey ||
|
|
'' === pvUserKey.trim() ||
|
|
'eMateOnepass_SSO' === pvUserKey
|
|
) {
|
|
keyBytes = ByteUtils.toBytesFromString('eMateOnepass_SSO');
|
|
ivBytes = ByteUtils.toBytesFromString('eMateOnepass_SSO');
|
|
} else if (
|
|
'201007GYCSSOPROJ' === pvUserKey ||
|
|
'201005KICSSOPROJ' === pvUserKey
|
|
) {
|
|
keyBytes = ByteUtils.toBytesFromString(pvUserKey);
|
|
ivBytes = ByteUtils.toBytesFromString(pvUserKey);
|
|
} else {
|
|
const bytes = ByteUtils.toBytesFromHexString(
|
|
CryptoJS.SHA1(pvUserKey).toString()
|
|
);
|
|
|
|
keyBytes = bytes.slice(0, 16);
|
|
|
|
ivBytes = ByteUtils.toBytesFromHexString(
|
|
CryptoJS.SHA1(ByteUtils.toHexString(bytes.slice(16, 20))).toString()
|
|
).slice(0, 16);
|
|
}
|
|
|
|
return {
|
|
key: keyBytes,
|
|
iv: ivBytes
|
|
} as CipherKeyDTD;
|
|
}
|
|
}
|