我已实施AES加密。请找到以下代码
import { Injectable } from '@angular/core';
import CryptoJS from 'crypto-js';
@Injectable()
export class AesProvider {
key: any = '';
constructor() {
this.key = 'asfda75vzv866@#$#';//CryptoJS.enc.Hex.parse("asfda75vzv866@#$#");
}
padOrTruncate(str: string): string {
let result: string = '';
if (str.length % 32 == 0)
return str;
result = str + '';
while (!(result.length % 32 == 0)) {
result = result + " ";
}
return result;
}
encrypt(plainText): string {
let text = this.padOrTruncate(plainText);
let encrypted = CryptoJS.AES.encrypt(text, this.key, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.NoPadding
});
return CryptoJS.enc.Hex.stringify(encrypted.ciphertext);
}
decrypt(encryptedText): string {
let decrypted = CryptoJS.AES.decrypt(encryptedText, this.key, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.NoPadding
}).toString();
//var plaintext = decrypted.toString(CryptoJS.enc.Utf8);
return decrypted;
}
}
问题是解密文本与纯文本不同。有人可以帮帮我吗?
谢谢和问候
驿站