[B@33bfc93a is encrypted (java)
szDataOut is
áÄóhçî¬ê¢h½qá!ëæQtA,dÐÒ
Completely different it seems until its base64? Not sure.. I'm not sure what exactly I should do here though..
Main Topics
Browse All TopicsI'm trying to get replicate encryption results for Java and C++ (So then I can decrypt or encrypt with either Java or C++)... I'm close but I believe this is a padding issue. However, I am not sure how to do it.
My goal is to use CBC or CFB (Prob CFB)... However, I am using ECB for now since it is more simple (Doesn't need IV/etc I believe.) Both are converted to base64 in the end.
I will provide both codes.. The results on this test are:
JAVA (ECB/NoPadding):
Output: 4cTzaH/n7oDqomi9ceEh6w==
C++ (CRijndael::ECB)
Output: 4cTzaH/n7oDqomi9ceEh6+ZRdI
There similarish but C++ seems to have more (Uses padding?) Pelase remember that the test value can be any length between 4-128 characters.. normally.
If anyone would help with CFB encryption that would be awesome too but I am not concerned about that yet. My goal is to make this work properly first then I can learn from it and expand.
Attached file: http://stellarfrontier.net
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
>>java code looks fine, though u shouldn't rely on the default character encoding and instead explicitly specify the encoding when converting between strings and byte arrays.
Accept Multiple Solutions
What do you mean exactly? Like using UTF?
>>good test would be to try and decrypt the encrypted string as see i you get the same back
I will try this soon, I do know if I decrypt it in java or C++ using the same encryption it works fine, haven't tested it through lets say, getting it in java and decrypting in C++ yet though.
Well the status update is.
I can convert from encrypt in C++ and decrypt in Java, and it seems fine.
However, If I encrypt in Java and decrypt in C++, I get the value
"aaaaaaaaaaaaaaaa6¤Ü´D<àdN
But the actual value is only 'aaaaaaaaaaaaaaaa'
Which is wierd.. Because Java is 'smaller', when encrypted it is: 4cTzaH/n7oDqomi9ceEh6w==
But in C++ the encrypted is: 4cTzaH/n7oDqomi9ceEh6+ZRdI
Those are the base64 results (just to state again).
However if I just do C++ encrypt and decrypt is works fine, same with java.
Oh the encryption part of C++? It is:
//One block testing
CRijndael oRijndael;
oRijndael.MakeKey("abcdefg
char szDataIn_Orig[] = "aaaaaaaaaaaaaaaa";
//Test ECB
int nLen = strlen(szDataIn_Orig);
int nBlockLen = ((int)nLen / 16 + 1) * 16;
char *szDataIn = new char[nBlockLen + 1];
memset((char *)szDataIn, 0, nBlockLen + 1);
strcpy(szDataIn, szDataIn_Orig);
// To encrypt
char szDataOut[17] ="\0";
oRijndael.Encrypt(szDataIn
std::string encoded = base64_encode(reinterpret_
then you can do the for(int i = 0;i < len(szDataOut);i++) { printf and get the data. which resulted in:
e1
c4
f3
68
7f
e7
ee
80
ea
a2
68
bd
71
e1
21
eb
e6
51
74
8d
41
2c
61
04
d0
d2
74
16
f7
28
22
8c
06
>>No- you should be printing the value of szDataOut as soon as encryption's been performed
Oh sorry, yes that what I was doing though, my bad on telling it like that!
About the hard coding, was just a quick test, I though it would be okay but I suppose I see now it's not. Do youmean the library (the encryption library) should give some length result for me to use?
Well it definatly has to be something then, With java just after encryption (No b64 yet)
e1
c4
f3
68
7f
e7
ee
80
ea
a2
68
bd
71
e1
21
eb
and C++, using the encrypted/base64ed java string, decrypted BASE64 is:
e1
c4
f3
68
7f
e7
ee
80
ea
a2
68
bd
71
e1
21
eb
Seems similar, so that rules out base64 doing it ;) I will give the nBlockLen and check!
That seemed to work, Output in C++ is now
4cTzaH/n7oDqomi9ceEh6w==
which is exact to the Java. I removed nblocklen, and just used nLen
int nLen = strlen(szDataIn_Orig);
char *szDataIn = new char[nLen + 1];
memset((char *)szDataIn, 0, nLen + 1);
strcpy(szDataIn, szDataIn_Orig);
// To encrypt
char szDataOut[17] ="\0\0\0\0\0\0\0\0\0\0\0\0
However, if I don't wish for it to be hard coded, would I do something similar to szDataOut and then set it with \0's? Java doesn't seem to be needed to be hardcoded so would be good to be similar.
Posted another, http://www.experts-exchang
Business Accounts
Answer for Membership
by: CEHJPosted on 2009-08-11 at 11:59:12ID: 25072188
Personally i would compare the results in 'szDataOut' and 'encrypted' first