🐞 fix(活动): 微信公众号口令加密去除补位
This commit is contained in:
@@ -51,23 +51,22 @@ export function aesDecryptcfb(data, key, iv) {
|
||||
|
||||
export function aes128Encrypt(input: string, key = '') {
|
||||
const cipher = crypto.createCipheriv('aes-128-ecb', key, null);
|
||||
let crypted = cipher.update(pkcs5_pad(input, 16), 'utf8', 'base64');
|
||||
let crypted = cipher.update(input, 'utf8', 'base64');
|
||||
crypted += cipher.final('base64');
|
||||
console.log('****aesEncryptcfb', 'input: ', input, 'crypted:', crypted)
|
||||
console.log('****aesEncryptecb', 'input: ', `"${input}"`, 'crypted:', `"${crypted}"`)
|
||||
return crypted;
|
||||
}
|
||||
|
||||
function pkcs5_pad(text: string, blocksize: number) {
|
||||
const pad = blocksize - (text.length % blocksize);
|
||||
return text + String.fromCharCode(pad).repeat(pad);
|
||||
}
|
||||
// function pkcs5_pad(text: string, blocksize: number) {
|
||||
// const pad = blocksize - (text.length % blocksize);
|
||||
// return text + String.fromCharCode(pad).repeat(pad);
|
||||
// }
|
||||
|
||||
export function aes128Decrypt(data: string, key = '') {
|
||||
const decipher = crypto.createDecipheriv('aes-128-ecb', key, null);
|
||||
let crypted = decipher.update(data, 'base64', 'utf8');
|
||||
crypted += decipher.final('utf8');
|
||||
const padding = crypted.charCodeAt(crypted.length - 1);
|
||||
// console.log('****aesEncryptcfb', data, crypted)
|
||||
return crypted.slice(0, -padding);;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user