digitalbazaar / forge

A native implementation of TLS in Javascript and tools to write crypto-based and network-heavy webapps
https://digitalbazaar.com/
Other
5.05k stars 779 forks source link

AES random decryption failure #1057

Open anisfaw opened 10 months ago

anisfaw commented 10 months ago

Hello everyone,

Im facing an issue while decrypting an "encryptedMessage" that occurs randomly using the following method :

METHOD :

    let decryptAES = function (encryptedMessage, key) {
        const decipher = forge.cipher.createDecipher('AES-ECB', forge.util.hexToBytes(key));
        decipher.start();
        decipher.update(forge.util.createBuffer(encryptedMessage));
        decipher.finish();
        return decipher.output.toHex();
    };

Valid decryption : let ktaDecrypted = decryptAES(forge.util.decode64('rplbhs67wEklyMANzB/I5Q=='), '61A402A2AD37BC383B1640BF40CB34E6'); Result : ktaDecrypted : 'd1f47b35ac2bce1ead510a73bf84a0e2'

Unvalid decryption : let ktaDecrypted = decryptAES(forge.util.decode64('Ky1HCLxXFKyY7O3Kcsq0OA=='), 'D610315807C4CEB945C7C10EE952D5B9'); Result : ktaDecrypted : ''

in this second case, i get an empty string as an outpu

Can anyone help with that ?

Note: on the other hand, the IOS Team could decrypt this correctly using the same informations.

pke commented 6 months ago

I encountered the same issue. It does work, with mode ECB/No Padding

https://gchq.github.io/CyberChef/#recipe=From_Base64('A-Za-z0-9%2B/%3D',true,false)AES_Decrypt(%7B'option':'Hex','string':'D610315807C4CEB945C7C10EE952D5B9'%7D,%7B'option':'Hex','string':'0000000000000000000000000000000'%7D,'ECB/NoPadding','Hex','Hex',%7B'option':'Hex','string':''%7D,%7B'option':'Hex','string':''%7D)&input=S3kxSENMeFhGS3lZN08zS2NzcTBPQT09