You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
840 B
29 lines
840 B
import CryptoJS from 'crypto-js';
|
|
|
|
import { BaseSymmetricEncryption } from '../base';
|
|
|
|
/**
|
|
* AES 实现
|
|
*/
|
|
export class AesEncryption extends BaseSymmetricEncryption {
|
|
override decrypt(data: string, key: string): string {
|
|
// 必须格式化字符串才能正常使用
|
|
const aesKey = CryptoJS.enc.Utf8.parse(key);
|
|
const decrypted = CryptoJS.AES.decrypt(data, aesKey, {
|
|
mode: CryptoJS.mode.ECB,
|
|
padding: CryptoJS.pad.Pkcs7,
|
|
});
|
|
return decrypted.toString(CryptoJS.enc.Utf8);
|
|
}
|
|
|
|
override encrypt(data: string, key: string): string {
|
|
// 必须格式化字符串才能正常使用
|
|
const aesKey = CryptoJS.enc.Utf8.parse(key);
|
|
const encrypted = CryptoJS.AES.encrypt(data, aesKey, {
|
|
mode: CryptoJS.mode.ECB,
|
|
padding: CryptoJS.pad.Pkcs7,
|
|
});
|
|
return encrypted.toString();
|
|
}
|
|
}
|