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.
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".
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 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?
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).
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...
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.
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.