Menu

AES-CBC and openSSL

Help
Anonymous
2012-06-07
2012-12-11
  • Anonymous

    Anonymous - 2012-06-07

    Hi, first of all i want to thank you for your great work.
    I have some trouble using your AES-CBC encryption class.
    On client side I have

        var data = get_unencrypted_data();
        var key_aes = generate_password(32);
        var aes = new pidCrypt.AES.CBC();
        aes.initEncrypt(data, key_aes, {nBits :256});
        var encrypted_data = aes.encryptRaw();
        encrypted_data = pidCryptUtil.encodeBase64(encrypted_data);
    

    And on the server side I have

      $unencrypted_data = openssl_decrypt($encrypted_data, 'aes-256-cbc', $aes_key,);
    

    But when i do this, i have an error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt and my $unencrypted_data is empty. Any idea?
    Thanks for your time

     
  • Anonymous

    Anonymous - 2012-06-07

    Ok, I didn't know that openSSL use salted data.
    aes.encrypt() encode in base64 if I'm not wrong, so I send to the server side the result of aes.encrypt() "as is".

    I started with this, now I have the same result than before :
    error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt

    I'm sure that my key are good, I even tried whit hardcoded key for the same result.
    Am I missing something?

     
  • Jonah (pidder)

    Jonah (pidder) - 2012-06-11

    Could you please check if you're able to decrypt the data using the openSSL commandline:

    echo "U2FsdGVkX1+7T7HYXNW8HpURIz0aa5a5kYMebhcemqOVks2Nqg9oWjG7qYfBSRcH"|openssl enc -aes-256-cbc -a -d
    

    If that works as expected, it is possible that the openssl_decrypt function you're using isn't working as expected. Assuming that you are using PHP's openssl_decrypt function, could you please check if the demo code at the end of this page does work for decrypting your input: http://php.net/manual/en/function.openssl-decrypt.php

     
  • Anonymous

    Anonymous - 2012-06-11

    Using openssl in commandline with 'password' work fine, but using this with openssl_decrypt return nothing (empty string, not bool(false))
    I tried with sqAES.decrypt and it work perfectly fine, so it seem it was openssl fault all this time. Sorry for cursing you ^^

    And again, thank for your time and your great work

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.