[Botan-devel] Encryption in java and decryption in C++

delannoy delannoy at toulouse.inra.fr
Tue Oct 18 09:17:43 EDT 2005


Hello,

I'm working on a project implemented in java (1.5) and c++ (3.3). The 
software is composed of a java interface which is running some C++ 
binaries. The program  contains more than one part. I would like to use 
a block cipher algorithm to filter the use of each part according to a  
user key delivered with the software.
For the moment, I'm generating a symmetric secret key with the Java 
Cryptography Extension. It works well! Then I'm generating a user key in 
java with a DES/CBC/PKCS5Padding algorithm which is working fine, it 
means that I'm doing the encryption in java.

However I need to do the decryption in C++ and I have some problems. I 
use the Botan 1.4.7 package and I don't succeed in decrypting the 
message with the same algorithm.

Example :
My java generated key is : 9d8ff7a4e575761f (See GenerateSecretKey.java 
in attachment)
Thanks to this key, i'm generating a symmetric user key :
message to encrypt : 141593
encrypted message : e410ac78755ab496
with algorithm : DES/CBC/PKCS5Padding (see SymmetricCipher.java for 
encryption and decryption)
When i decrypt the message, i obtain the original message.

My C++ code is :

#include <botan/base.h>
#include <botan/init.h>
#include <botan/des.h>
#include <botan/blowfish.h>
using namespace Botan;
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <botan/look_add.h>
#include <botan/lookup.h>
#include <botan/filters.h>

int main() {
   LibraryInitializer init;
   SymmetricKey key("9d8ff7a4e575761f");
   Pipe enc(get_cipher("DES/ECB/PKCS7", key, ENCRYPTION), new Hex_Encoder);
   Pipe dec(new Hex_Decoder, get_cipher("DES/ECB/PKCS7", key, DECRYPTION));
   std::string secret = 141593;
   std::cout << "The secret message is '" << secret << "'" << std::endl;
   enc.process_msg(secret);
   std::string cipher = enc.read_all_as_string();
   std::cout << "The encrypted secret message is " << cipher << std::endl;
   dec.process_msg(cipher);
   std::string bubu = dec.read_all_as_string();
   std::cout << "The decrypted secret message is '"<< bubu << "'" << 
std::endl;
}

The encrypted message by C++ and Java is not the same, when message is 
141593 and using the same key.
Do you think it's possible de encrypt in java and decrypt in C++? If 
yes, any idea on what's wrong with my algorithm?

Note that, when I try to decrypt the java encrypted message in C++ , I 
get the following error "decoding error : PKCS7".
Thank you very much for your help.

David

-- 
David Delannoy
INRA,BIA, BP27 31326 Castanet-Tolosan, France.
Phone: +33 5 61 28 50 71
Fax: +33 5 61 28 53 35 
mailto:delannoy at toulouse.inra.fr

-------------- next part --------------
A non-text attachment was scrubbed...
Name: GenerateSecretKey.java
Type: text/x-java
Size: 1841 bytes
Desc: not available
URL: <http://lists.randombit.net/pipermail/botan-devel/attachments/20051018/6c002b90/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: GenerateUserKey.java
Type: text/x-java
Size: 3517 bytes
Desc: not available
URL: <http://lists.randombit.net/pipermail/botan-devel/attachments/20051018/6c002b90/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SymmetricCipher.java
Type: text/x-java
Size: 3429 bytes
Desc: not available
URL: <http://lists.randombit.net/pipermail/botan-devel/attachments/20051018/6c002b90/attachment-0002.bin>


More information about the botan-devel mailing list