views:

150

answers:

5

What algorithm can I use for creating an encryption program in Java? What if I want to use the same key for encrypting and decrypting?

Example: I type Hello world and use the key guy, so the words change into xgdsts@dtoll. If I want to decrypt it, I have to use the same key(guy) so it'll become hello world again

+2  A: 

You could use AES.

Darin Dimitrov
thanks for the reply Dimitrov, i'll googling it about AES...
WenZ
@WenZ, try the link I have posted. It contains a sample.
Darin Dimitrov
+1  A: 

Take a look at the Java Cryptography Extension. Here's a simple example.

SB
+2  A: 

You can use any algorithm you want, if you're willing to implement it. If you're asking what algorithms Java provides, the cryptography extension offers (from this list):

  • AES
  • Blowfish
  • DES
  • DESede
  • RC2, RC4, RC5
  • RSA

I believe all those are symmetric (the encryption and decryption key is the same) except for RSA

Michael Mrozek
That link is to the Java 1.4 documentation. I haven't looked around, but you might want to either annotate that or link to a more recent version of that documentation.
Thomas Owens
@Thomas I'm having trouble finding the newer documentation, but I added a note in the answer
Michael Mrozek
You might want to check it out to verify, but http://download.oracle.com/javase/6/docs/technotes/guides/security/crypto/CryptoSpec.html appears to be the Java 6 version of what you linked to.
Thomas Owens
@Thomas Score. Updated, thanks
Michael Mrozek
A: 

You can use any symmetric key algorithm

Zenzen
A: 

I would stick to the industry standards - Triple-DES (3DES) or AES, whereby 3DES is slowly being replaced by AES. Libraries and source code for various languages are available, tested and validated.

I would use random generated keys for data encryption, and distribute these keys using asymetric methods (RSA) based on public/private key pairs.

MikeD