On Sun, Feb 28, 2010, ashuahen wrote:
>
> I am using AES_CBC with padding (using PKCS#5 to pad) on C++ side:
>
> AES_set_encrypt_key( keyBuf, 128, &key )
> keyBuf contains key string
> key is the key generated
>
> Block Lenght is 16
>
> AES_cbc_encrypt (ibuf, obuf, lenpad, &key, iv, AES_ENCRYPT)
> ibuf = input data
> obuf = encrypted data
> lenpad = length of data (input data length + pad data length)
> key = key generated by AES_set_encrypt_key
> iv = initialization vector
>
> On java side:
> I am decrypting using following:
>
> SecretKey aesKey = new SecretKeySpec(KeSo.getKey(keyBuffer), "AES");
> keyBuffer: is same as KeyBuf @ C++ side
>
> Cipher cipherDec = Cipher.getInstance("AES/CBC/PKCS5Padding", "BC");
> cipherDec.init(Cipher.DECRYPT_MODE, aesKey, iv);
> cipherDec.doFinal(enc);
> enc: data to be encrypted in byte.
>
> Problem
> =======
>
> I was using libcrypto.0.9.8a and every thing was working fine.
> But as a part of upgrade on Sun SPARC licrypto0.9.8a is changed to
> libcrypto.0.9.8k and things became worst. Encryption is not giving any
> problem but during decryption with the same code I am getting
> BadPaddingException.
>
> Please help me out, this problem has made my life hell.
>
You really shouldn't use the low level ciphers directly as we've advised for
some years:
http://www.openssl.org/docs/crypto/EVP_EncryptInit.html#NOTES
That would for example have taken care of PKCS#5 padding automatically and
allowed the use of external crypto hardware for the operation.
As for your problem. I'd suggest decrypting with the current and older
versions of OpenSSL and seeing if that works.
Steve.
--
Dr Stephen N. Henson. OpenSSL project core developer.
Commercial tech support now available see: http://www.openssl.org
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [email protected]
Automated List Manager [email protected]