Я видел nodejs и онлайн разные , но все еще не могу понять. Я использую C ++ Poco и Nodejs, даже использую «aes-128-ecb», а 16-байтовые пароли все равно имеют разные.
Вот коды ниже:
Nodejs
var crypto = require('crypto'),
algorithm = 'aes-128-ecb',
password = '123451234567890a';
function encrypt(text){
var cipher = crypto.createCipher(algorithm,password)
var crypted = cipher.update(text,'utf8','base64')
crypted += cipher.final('base64');
return crypted;
}
function decrypt(text){
var decipher = crypto.createDecipher(algorithm,password)
var dec = decipher.update(text,'base64','utf8')
dec += decipher.final('utf8');
return dec;
}
var hw = encrypt("8c:85:90:48:d8:51")
console.log(hw)
console.log(decrypt(hw));
Poco
Poco::Crypto::Cipher::Ptr pCipher =
CipherFactory::defaultFactory().createCipher(
CipherKey("aes-128-ecb", "123451234567890a"));
string out = pCipher->encryptString("8c:85:90:48:d8:51", Cipher::ENC_BASE64);
string result = pCipher->decryptString(out, Cipher::ENC_BASE64);
cout << result << endl;
cout << "after encrypt: " << out << endl;
На самом деле онлайн-результат также отличается.
Спасибо за вашу помощь!