Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
john sal
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Beginning Cryptography with Java" by David Hook published by Wrox.
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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........
 
john sal
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you guide me to some tutorials so that i can understand it better and can implement it.
 
john sal
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic