• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to recreate DESede that was created 12 years ago - Is my logic correct?  RSS feed

 
Daniel Barry
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Forgive my lack of knowledge, I'm new to encryption.

I have a Java app from a dozen years ago that uses a BouncyCastle jar from 2005 (or so) to create a symmetric key using DESede and encode plaintext.

Parameters for Symmetric Encryption/Decryption:

    symmetric encryption: DESede
    symmetric decryption: DESede/ECB/NoPadding

My understanding for Java DESede:

  2 Key blocks are used (Three keys exist,  k1,k2,k3. Where k1=k3 and k1 <> k2.
  The Key blocks are all 8 Bytes long, but only use the frst 7 Bits of each byte (56 Bits for each key).

My struggle:
    (I am actually recreating this in C#, and I cannot change the source code that is decrypting this... I don't even have access to it) - I know this is a Java site, but as the code is java from 12 years ago, I was hoping someone might understand how Java creates and uses the DESede keys (so I could recreate in C# and have them match... currently they do not match    )

It is tough to find clear docs (I've looked at the Javadocs, but I still don't fully understand -
    I have recreated the Java code and it works (based on the bouncyCastle jar that was used back in 2005, but cannot share publicly as the original Java code is proprietary.


My questions:
    1) Do I need to address the parity issue? I have matched up the hex of the symmetric key between Java and C# and they match. But I'm not sure if that carries any weight. If I have to adjust parity, how is this done?
2) The decryption algorithm specifies ECB and NoPadding, but it seems the if I don't use PKCS7 Padding, it triggers an exception. Is it OK to use PKCS7?
3) Do I use EBC for encrypting?


Code:



Based on the variables in the C#, I should get the following output (encrypted String):
   pxBkN045vgiy5VaYijCsx7XeYsnTutX9

But I get this when I run the C#:

  gXSUXjraUG+XwNSsEIAArJPZb6J6qI1M

Same # of characters, but wildly different string....

Please let me know if any more clarification would be helpful.

Thanks,


 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bouncy Castle is an open source library and there's even a C# implementation of it, so maybe what you are trying to do is already implemented in the C# version of Bouncy Castle. I would research that first before trying to implement this yourself.

Encryption algorithms can be very complex and depend on lots of details, and it's hard to implement them correctly yourself.
 
Daniel Barry
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Daniel Barry wrote: Nothing to quote - just an update!! (New to this format also)... I will learn I promise!!!





Based on the variables in the C#, I should get the following output (encrypted String):
   I now the get same string ... almost... in C#... there is a single forwardslash "/"
   In Java (there is a "%2F" (after the first block) and a "%2B" after the second block and at the end C# has an "=" sign and the Java has "%3D"

Any ideas for correcting to replace the "/" with "%2B" etc?
 
Daniel Barry
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Daniel Barry wrote:


Based on the variables in the C#, I should get the following output (encrypted String):
   I now the get same string ... almost... in C#... there is a single forwardslash "/"
   In Java (there is a "%2F" (after the first block) and a "%2B" after the second block and at the end C# has an "=" sign and the Java has "%3D"

Any ideas for correcting to replace the "/" with "%2B" etc?


Encoded it and all is well! Issue resovled.

Thanks for your time!!!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!