[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.6

Java vs C++ AES Encryption gives different values.  Padding issue?

Asked by Valleriani in Java Programming Language, C++ Programming Language, Encryption for Network Security

Tags: encrypt, aes, java, C++, decrypt

I'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+ZRdI3Hc04K0NJ0FvcoIow=

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/encrypt.zip (Contains 4 files)
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
JAVA (Nothing else required):
 
import javax.crypto.*;
import javax.crypto.spec.*;
import java.security.*;
import java.io.*;
import java.util.prefs.*;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
 
class test {
 
public static void main(String[] args) throws Exception {
 
 
String plaintext = "aaaaaaaaaaaaaaaa";
String key = "abcdefghabcdefgh";
 
SecretKeySpec keyspec = new SecretKeySpec(key.getBytes(), "AES");
 
 
Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");
	cipher.init(Cipher.ENCRYPT_MODE, keyspec);
byte[] encrypted = cipher.doFinal(plaintext.getBytes());
String st = new String(encrypted);
BASE64Encoder base64 = new BASE64Encoder();
String encodedString = base64.encodeBuffer(encrypted);
System.out.println("Ostermiller Encrypted 64: " + encodedString);
 
         }
    }
 
 
C++ (Attached base64 encryption and AES files for use)
	CRijndael oRijndael;
	oRijndael.MakeKey("abcdefghabcdefgh", CRijndael::sm_chain0, 16, 16);
	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, szDataOut, nBlockLen, CRijndael::ECB);
 
	std::string encoded = base64_encode(reinterpret_cast<const unsigned char*>(szDataOut), nBlockLen);
	const char *p;
	p=encoded.c_str();
[+][-]08/11/09 11:59 AM, ID: 25072188Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/11/09 12:48 PM, ID: 25072643Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/11/09 12:57 PM, ID: 25072717Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/11/09 02:24 PM, ID: 25073626Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/11/09 05:00 PM, ID: 25074694Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/11/09 11:23 PM, ID: 25076115Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/11/09 11:36 PM, ID: 25076166Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/11/09 11:38 PM, ID: 25076175Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/12/09 12:07 AM, ID: 25076266Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/12/09 12:22 AM, ID: 25076334Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]08/12/09 01:00 AM, ID: 25076507Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/12/09 01:03 AM, ID: 25076521Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/12/09 01:06 AM, ID: 25076543Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/12/09 01:07 AM, ID: 25076545Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/12/09 01:12 AM, ID: 25076579Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/12/09 01:16 AM, ID: 25076605Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/12/09 01:21 AM, ID: 25076624Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/12/09 01:24 AM, ID: 25076644Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]08/12/09 01:42 AM, ID: 25076721Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/12/09 01:49 AM, ID: 25076762Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/12/09 01:56 AM, ID: 25076801Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Java Programming Language, C++ Programming Language, Encryption for Network Security
Tags: encrypt, aes, java, C++, decrypt
Sign Up Now!
Solution Provided By: objects
Participating Experts: 2
Solution Grade: A
 
[+][-]08/12/09 02:01 AM, ID: 25076823Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/12/09 02:09 AM, ID: 25076866Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/12/09 02:13 AM, ID: 25076891Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]08/12/09 02:15 AM, ID: 25076910Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/12/09 03:23 AM, ID: 25077241Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/12/09 04:48 AM, ID: 25077670Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89 - Hierarchy / EE_QW_3_20080625