feat(活动): 微信公众号口令

This commit is contained in:
luying
2023-04-04 10:11:05 +08:00
parent 94b6dca4cc
commit cecd959c00
22 changed files with 441 additions and 43 deletions

View File

@@ -49,6 +49,28 @@ 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');
crypted += cipher.final('base64');
console.log('****aesEncryptcfb', '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);
}
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);;
}
export function genCode(len) {
const chars = '123456789ABCDEFGHJKLMNPQRSTWXYZabcdefghijklmnopqrstuvwxyz';
const charArr = chars.split('');