aspose file tools*
The moose likes Java in General and the fly likes Need to write java code for encryption and decryption of a file. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Need to write java code for encryption and decryption of a file." Watch "Need to write java code for encryption and decryption of a file." New topic
Author

Need to write java code for encryption and decryption of a file.

john sal
Ranch Hand

Joined: Jul 30, 2010
Posts: 92
I need to write a java code for encrytpion and decryption of a file.

I need to encrypt a file using some predefined key and need to decrypt the same using that key.

Can someone guide me how can i do that or share the sample code for the same.

It is like read a file encrtpt the content using predefined key and write it back.

Now read the encrypted file decrypt it using the key and write it back.
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

"Beginning Cryptography with Java" by David Hook published by Wrox.


Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
The standard Java API for en-/decryption is called JCE, and it's part of JSE. See the SecurityFaq for more material about it. An algorithm like AES or TripleDES would work.
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

above will be a good solution but if you really want to do that manually.....using your own keys and value then use hashmap..

but i think that should not be a good solution to use hashmap for encryption and decryption........


SCJP6.0,My blog Ranchers from Delhi
john sal
Ranch Hand

Joined: Jul 30, 2010
Posts: 92
Can you guide me to some tutorials so that i can understand it better and can implement it.
john sal
Ranch Hand

Joined: Jul 30, 2010
Posts: 92
Now the problem is that i need to encrypt the file at one system and want to decrypt at other system. So i need to have the same key for encryting and decrypting the data.

The algorithm i am using is DES encryption. Is there any way so that we give the key ourself instead of generating it randomly?
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
Don't use DES, it's too weak these days. Triple-DES (or "DESede", as it's called in JCE lingo) should be fine if you don't want to use AES.

The FAQ I pointed you to has an article that show how to use a pre-determined key instead of a random one with DES (in the JCE section); it works the same for Triple-DES.
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

pintoo saluja wrote:Now the problem is that i need to encrypt the file at one system and want to decrypt at other system. So i need to have the same key for encryting and decrypting the data.

The algorithm i am using is DES encryption. Is there any way so that we give the key ourself instead of generating it randomly?


Yes - but I'm not willing to just provide code. You need to spend a lot of time reading and the book I cited is a very good starting point.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need to write java code for encryption and decryption of a file.
 
Similar Threads
AES SecretKeySpec object varies in two instances with same passphrase.
Ciphering a Serailized Object
Decryption of file is taking too much time.
"javax.crypto.BadPaddingException: pad block corrupted" using BouncyCastle and DESede: How to avoid?
md5 decryption