Jo wrote:
> I have designed and implemented the symmetric AES crypto algorithm in a
> Java-application and in a C++ application.
>
> My C++-application uses the Library crypto++, version 5.2.1 and i use
> the AES functionality of this Library.
> It works fine, i can encrypt and decrypt any texts.
>
> My Java-application uses the Java Framework "JCE" with the Library
> bounce castele and i use the AES functionality of this Library. It
> works fine, i can encrypt and decrypt any texts.
>
> If i use in my Java-application the secrete key with the assoziated
> encrypted text generated in my C++-application, my Java-application
> crashes with the Exception "BadPaddingException: pad block corrupted".
> If i use in my C++-application the secrete key with the assoziated
> encrypted text generated in my Java-application, my C++-application
> crashes with the Exception "StreamTransformationFilter invalid PKCS#7
> block padding found"
>
> In the Java Library bouncy castle i have found the implemented S-box
> and the invert S-box, but in the Library crypto++ i did not found it.
> Is it possible that in the crypto++ Library is used an other
> Implementation of the AES/Rijndael Algorithmus without need of use
> S-boxes ?
Crypto++ probably uses a large table version of AES, which means that
you won't find the S-Box in the code in an obvious form.
> How can I found which Library is wrong or what is the cause for my
> problem ?
The most likely cause of your problem is not in the libraries but in the
code that you are using to interface with them. You need to check that
you are using the same cryptographic modes, the same padding conventions
etc. in order to ensure that the encrypted texts for the two
applications are compatible with each other.
> My Implementation of the decrypt Methode which uses the crypto++
> Library
> void DecryptorSymImpl::decrypt(const string &crCipherTxt, string
> &rDecryptedTxt) const {
>
> const byte *keyAsByte = reinterpret_cast<const
> byte*>(this->key.getEncoded().data());
> //convert crCipherTxt from hex in binary and convert it from string
> to byte*
> string cipherTxtAsBinaryTmp;
> StringSink *cipherTxtSink = new StringSink(cipherTxtAsBinaryTmp);
> HexDecoder *cipherTxtAsBinary = new HexDecoder(cipherTxtSink);
> StringSource(crCipherTxt, true, cipherTxtAsBinary);
> const byte *cipherTextAsByte = reinterpret_cast<const
> byte*>(cipherTxtAsBinaryTmp.data());
> //decrypt the cipherTxt with the secreteKey
> AES::Decryption aesDecryption(keyAsByte, this->key.getLength()/8);
> CBC_Mode_ExternalCipher::Decryption cfbDecryption(aesDecryption,
> Cryptor::iv);
> StringSink *decryptedTextSource = new StringSink(rDecryptedTxt);
> StreamTransformationFilter stfDecryptor(cfbDecryption,
> decryptedTextSource);
> stfDecryptor.Put(cipherTextAsByte, crCipherTxt.length()/2);
> stfDecryptor.MessageEnd();
> }
The conventions here for "strings", for conversions from strings to
arrays of hex digits, for cipher mode (CFB above) and many other things
all have to match precisely in your two applications. This is where I
would expect to find the sort of problem you are facing.
Brian Gladman
Received on Fri Dec 23 20:11:31 2005