Hello
Please be patient with me because I'm new to cryptographic .
What I want wo achive:
We have a Windows MFC Application (VC 6.0) where we use a licenc file
The file should be encrypted with AES (Rijndeal), in C++ it works fine.
(I used the Cryptolib and I'm able to ecnrypt&decrypt files,
bytearrays, strings....)
The problem is we need an JAVA app to create such licenc files
(through a Web/Application Server)
My Status:
I'm able to encode/decode bytearrays in Java with AES
I'm able to encode/decode bytearrays in C++ with Crypto++ (with
Crypto 4.2 because of VC 6.0)
but I'm not able to encode in Java and decode in C++, or vice versa ?
My C++ Code:
#################################################
byte m_UserKey[17];
memset(m_UserKey,1,sizeof(m_UserKey));
byte iv[16];
byte inputstring[100];
byte xxxbuf[100];
memset (inputstring,0,sizeof(inputstring));
memset (iv,0,sizeof(iv));
strncpy ((char *)inputstring,m_to_encrypt,m_to_encrypt.GetLength());
AESEncryption aesEncryption(m_UserKey, 16);
CFBEncryption cfbEncryption(aesEncryption, iv);
//CBCPaddedEncryptor cbcEncryptor(aesEncryption, iv, new
ArraySink(xxxbuf,sizeof(xxxbuf)));
//cbcEncryptor.Put(inputstring, m_to_encrypt.GetLength());
// input more plaintext here if needed
//cbcEncryptor.MessageEnd();
cfbEncryption.ProcessString(inputstring,16);
//memcpy(inputstring,xxxbuf,sizeof(xxxbuf));
m_encrypted=CString(inputstring);
m_encrypted_hex=byteArraytoHexString(inputstring,16);
################################################
to keep it simple i set IV to 000000.....
in Java (with Version 1.4.2..):
################################################
String message="abcdefgaijklmnop";//"This is just an example";
byte the_key[] = new byte[16];
byte idx=0;
the_key[idx++] =(byte)0X01;
the_key[idx++] =(byte)0X01;
the_key[idx++] =(byte)0X01;
the_key[idx++] =(byte)0X01;
the_key[idx++] =(byte)0X01;
the_key[idx++] =(byte)0X01;
the_key[idx++] =(byte)0X01;
the_key[idx++] =(byte)0X01;
the_key[idx++] =(byte)0X01;
the_key[idx++] =(byte)0X01;
the_key[idx++] =(byte)0X01;
the_key[idx++] =(byte)0X01;
the_key[idx++] =(byte)0X01;
the_key[idx++] =(byte)0X01;
the_key[idx++] =(byte)0X01;
the_key[idx++] =(byte)0X01;
SecretKeySpec skeySpec =new SecretKeySpec(the_key,"AES");
// Instantiate the cipher
Cipher cipher = Cipher.getInstance("AES/CFB/NoPadding");
//Cipher cipher = Cipher.getInstance("AES");
byte iv[]= new byte[16+2];
for (int i =0;i<iv.length;i++)
{
iv[i]=0;
}
iv[0]=4;
iv[1]=0x10;
AlgorithmParameters myparam = AlgorithmParameters.getInstance("AES");
myparam.init(iv);
cipher.init(Cipher.ENCRYPT_MODE, skeySpec,myparam);
System.out.println("IV: "+asHex(cipher.getIV()));
System.out.println("Param: "+myparam);
byte[] encrypted =
cipher.doFinal((args.length == 0 ?
message : args[0]).getBytes());
System.out.println("encrypted string: " + asHex(encrypted));
cipher.init(Cipher.DECRYPT_MODE, skeySpec,myparam);
byte[] original =
cipher.doFinal(encrypted);
String originalString = new String(original);
System.out.println("Original string: \"" +
originalString + "\" " + asHex(original));
################################################
I tried different approaches (CFB, CBC, different Blocksizes, different IV)
but I don't come to any successfull encryption/decryption
Can somebody tell me, what I'm doing wrong?
(probably I should use a simpler algorithmen then AES but which algo?)
--
+--------------------------------------------------------+
|Thek Norbert Alexander ICQ# 11673043 |
|mailto:[EMAIL PROTECTED] |
+--------------------------------------------------------+
Programmer: The device for converting coffee into software