[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.8

C++/Java AES Encryption: CFB IV key issues?

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

Related Question Here: http://www.experts-exchange.com/Programming/Languages/Java/Q_24644152.html

I have finished with Java and C++ encryption using ECB, one of the more simple encryptions of AES.

However, CBC and CFB require a IvParameterSpec/Chain to function properly.

I am not sure how to go about this, for C++, I've done, when making the key:

      oRijndael.MakeKey("abcdefghabcdefgh", CRijndael::sm_chain0, 16, 16);

   sm_chain0 being a simple: \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0 for use.  I also have to reset the chain using     oRijndael.ResetChain(); every time I need to encrypt/decrypt.


C++ sample:"
      CRijndael oRijndael;
      oRijndael.MakeKey("abcdefghabcdefgh", CRijndael::sm_chain0, 16, 16);
      char szDataIn_Orig[] = "aaaaaaaaaaaaaaaa";

        //Test ECB
      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\0\0\0\0";
    oRijndael.ResetChain();
      oRijndael.Encrypt(szDataIn, szDataOut, nLen, CRijndael::CFB);

      std::string encoded = base64_encode(reinterpret_cast<const unsigned char*>(szDataOut), nLen);
"


java sample:

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 test2 {

public static void main(String[] args) throws Exception {


String plaintext = "abcdefghabcdefgh";
String key = "abcdefghabcdefgh";

            byte iv[16];

for (int i =0;i<iv.length;i++)
{
iv[i]=0;
}

IvParameterSpec ivParameterSpec = new IvParameterSpec(iv);

SecretKeySpec keyspec = new SecretKeySpec(key.getBytes(), "AES");


Cipher cipher = Cipher.getInstance("AES/CFB/NoPadding");
      cipher.init(Cipher.ENCRYPT_MODE, keyspec, ivParameterSpec);
byte[] encrypted = cipher.doFinal(plaintext.getBytes());
String st = new String(encrypted);
System.out.println("Ostermiller Encrypted 64: " + encrypted);

BASE64Encoder base64 = new BASE64Encoder();
String encodedString = base64.encodeBuffer(encrypted);
System.out.println("Ostermiller Encrypted 64: " + encodedString);


         }
    }


Would be example coding for the encoded. Using  CRijndael::ECB for C++ and AES/ECB/NoPadding for java works great. However, swappingt o CFB or CBC that eneds the IV key does not work well.

Any suggestions on how I can get the 'keys' synced up? I am maybe thinking the java side key isn't working properly, as I'm not to well (just started a couple days ago) with java.

The general attached files like before are still at http://stellarfrontier.net/encrypt.zip (Contains 4 files for C++)
 
Related Solutions
Keywords: C++/Java AES Encryption: CFB IV …
 
Loading Advertisement...
 
[+][-]08/12/09 03:24 AM, ID: 25077245Author 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:31 AM, ID: 25077279Expert 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 04:38 AM, ID: 25077600Author 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:41 AM, ID: 25077620Accepted 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: Encryption for Network Security, C++ Programming Language, Java Programming Language
Sign Up Now!
Solution Provided By: objects
Participating Experts: 1
Solution Grade: A
 
[+][-]08/12/09 04:49 AM, ID: 25077682Author 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:57 AM, ID: 25077730Expert 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 05:07 AM, ID: 25077799Author 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 05:19 AM, ID: 25077888Author 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.

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