This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Encrypt and decrypt using Open SSL

 
Ashok Kumar Segu
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Is is possible to encrypt message in java and decrypt the message using openssl (DES_ede2_cbc_encrypt) and the key is our own private key, vice versa

Has any one implemented the same
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by "in java"? OpenSSL is not written in Java. Are you asking whether OpenSSL can be run through Java code? If so, check out the Runtime.exec method and the ProcessBuilder class. if you meant something else, please provide more detail.
 
greg stark
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
actually, I think I understand the first part of the question but I am not certain about the second part. Private key means something very specific in cryptography, namely the private component of an asymmetric keypair. Perhaps you mean secret key, which is the key for a symmetric algorithm like DES_ede2.

The general answer is yes, of course, people have implemented cryptography in Java that is interoperable with OpenSSL-based cryptography. The devil is in the details, as always.
 
Ashok Kumar Segu
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
greg stark wrote:actually, I think I understand the first part of the question but I am not certain about the second part. Private key means something very specific in cryptography, namely the private component of an asymmetric keypair. Perhaps you mean secret key, which is the key for a symmetric algorithm like DES_ede2.

The general answer is yes, of course, people have implemented cryptography in Java that is interoperable with OpenSSL-based cryptography. The devil is in the details, as always.


If am able to encrypt and decrypt using open ssl DES_ede2_cbc_encrypt (key1, key2 i.e. 2DES) and it works fine, my requirement I need to encrypt the message using Java Cipher or any other compatible crypto toll to encrypt the message (2DES key) , the other end uses openssl to decrypt the same (using the same 2DES key)
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may want to work through this thread, which explains a number DES details, including how to use 112-bit DES (which I assume is what you mean by 2-DES) in Java: http://www.coderanch.com/t/447399/Security/bit-DES-encryption-decryption
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ashok Kumar Segu wrote: my requirement I need to encrypt the message using Java Cipher or any other compatible crypto toll to encrypt the message (2DES key)


Is this to inter-operate with some ancient software? Otherwise, I can't think of any reasons to write code today using DES (or 2DES). DES has been obsolete for over a decade. For new software projects, use something more current.
 
Henry Wong
author
Marshal
Pie
Posts: 21506
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ashok Kumar Segu wrote:If am able to encrypt and decrypt using open ssl DES_ede2_cbc_encrypt (key1, key2 i.e. 2DES) and it works fine, my requirement I need to encrypt the message using Java Cipher or any other compatible crypto toll to encrypt the message (2DES key) , the other end uses openssl to decrypt the same (using the same 2DES key)


I believe what you are describing is still triple DES (3DES) -- basically, it does an encrypt with key 1, a decrypt with key 2, and an encrypt with key 1. The "triple" in the triple DES is referring to the number of DES operations, and not the number of keys.

I believe the Java version of triple DES (included in the core), is also ede, but uses three DES keys. So... if you try having the first and last third part of the 3 DES key being equal, it may work. You won't know til you try it though.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic