Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Triple DES encrytpion and decryption using 256 bit and 512 bit

 
Elangeswaran kangaraj
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am new to 3DES algorithm with encryption and decryption. I want to know how we encrypt and decrypt a data based on the key with 256 and 512 bit format using Triple DES (3DES). I want Code sample for the above concept.

I need this sharing in soon....

I expect your valuable reply in soon.

Thanks int Advance,
K.Elanges
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TripleDES does not use those key sizes. It uses 168 bit (DES uses 56 bit, and TripleDES uses 3 times that - hence its name). An example of using DES can be found here. Using TripleDES instead would involved replacing the "DES" cipher designation by "DESede".
 
Elangeswaran kangaraj
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am new to 3DES , thats why i asking this question. kindly send the code sample for 3DES to key based encryption and decryption with specified bit key length.

Thanks in advance...

Regards
K.Elanges
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not how JavaRanch works. Instead of writing the code for you, we try to help you write the code yourself. But -if you look at the link I posted- there's hardly anything left to write. Just change the cipher designator accordingly, and you're done. If you're unsure about what that entails I suggest that you read up on JCE (the Java API for encryption) so you understand what's going on. It's easy to get encryption wrong (and thus insecure) if one doesn't understand what's happening underneath; start here.
 
Elangeswaran kangaraj
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ulf Dittmer

i have done the following for 3DES. But i want to know how we specify key bit length for encryption and decryption.




Your valuable ideas will be very help to me.
Thanks in advance.
Regards,
L.Elanges
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With DES and TripleDES you don't specify the key length, because they're fixed. See my first post.
 
Elangeswaran kangaraj
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ulf Dittmer,

Thanks for your quick reply. I want to use Triple DES and key length should be following 16,32,64,128,256 and 512. Bit value may be we read from a properties files.

Kindly tell me how we implement...

Thanks in Advance.

Regards,
K.Elanges
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which part of
TripleDES does not use those key sizes. It uses 168 bit (DES uses 56 bit, and TripleDES uses 3 times that - hence its name).

and
With DES and TripleDES you don't specify the key length, because they're fixed.

are you having trouble understanding? You can consult Wikipedia if you don't believe me.
 
Henry Wong
author
Marshal
Pie
Posts: 20894
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Elangeswaran kangaraj wrote:
Thanks for your quick reply. I want to use Triple DES and key length should be following 16,32,64,128,256 and 512. Bit value may be we read from a properties files.

Kindly tell me how we implement...


As Ulf mentioned, TripleDES uses 168 bit keys. With the Java implementation, this is spread out over 24 bytes. So... if you want to have the key lengths, that you can specify, you will have to create a way to convert those key lengths to 24 bytes. This is not specific to 3DES, you will have to invent something yourself -- maybe you can send the bits to a hashing algorithm (like SHA1) and take the 24 bytes from that?

Henry
 
Elangeswaran kangaraj
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi Ulf Dittmer,

I have hope with you. can you share with me other than 3DES algorithm how we encrypt a data based on a static key with specified bit size. Assume the bit size is available in a properties file.

I expect you favorable reply. If you provide code for that it would be very helpful to me.

Thanks in advance.

Regards,
K.Elanges
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know how else to say that what you're asking is impossible. You need to read up on how DES and TripleDES work. It's dangerous to use encryption without understanding how it works (meaning it's easy to implement something that's not really secure).
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Blowfish can have a key of up to 448 bits, and is supported by the javax.crypto package.
 
Elangeswaran kangaraj
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi Ulf Dittmer.

I understand your suggestions and all. If we could not use 3DES with key size as 256 or 512 bit means there are any other algorithms for this requirement that is my intention. So, I asked with you.... Kindly suggestion me...

Thanks in advance.

Rgards,
K.Elanges
 
Carey Evans
Ranch Hand
Posts: 225
Debian Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The supported encryption algorithms for Sun Java are listed in the Sun Providers Documention, including the supported key lengths. If you don't want to use standard algorithms like 3DES or AES with restricted key sizes, you could choose Blowfish or RC4.

Bear in mind that RC4 is remarkably easy to use insecurely, as in the WEP protocol. In addition, RC2 was designed so that the NSA could break it 20 years ago if it used 40 bit keys, and any algorithm using keys shorter than 128 bits is going to be fairly vulnerable today.
 
Henry Wong
author
Marshal
Pie
Posts: 20894
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Also keep in mind that algorithms are not equal -- ie. key lengths are not equal. Meaning a 256 bit key length with one algorithm may be as secure as a 1024 bit key length with another algorithm. It is kinda silly to pick an algorithm purely for it's support of a particular key length.

Henry

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic