Security
can some one show me a code and how to
encrypt password using the java.crypto
package. how do i implement a provider.
what is the best algorithm to use.
Web Development
can some one show me a code and how to
encrypt password using the java.crypto
package. how do i implement a provider.
what is the best algorithm to use.
by jay eckles
First, there is no java.crypto package. You probably mean one of two things: java.crypt or javax.crypto.
I've fiddled around with this some using MD5 encryption...store an MD5 encrypted version of the password on the server, then encrypt the password received and compare it to the encrypted version on the server...that way the cleartext password isn't stored on the server. But I digress...
First of all, have a look at the javax.crypto.cipher documentation at
http://java.sun.com/products/jce/doc/apidoc/javax/crypto/Cipher.html
and the java.crypt documentation at
http://tinf2.vub.ac.be/~dvermeir/java/cryptix/doc/Package-java.crypt.html
Taking some examples from the docs, you might do something like this:
Cipher c = Cipher.getInstance("DES/CBC/PKCS5Padding");
to get a DES chain-block cipher with PKCS5 padding (whatever PKCS5 is). If you wanted to just get MD5 digests, you might do something like this:
Cipher c = Cipher.getInstance( "MD5" ) ;
Depending on the algorithm you choose, you might have to do a c.init() call, in most cases you'll do a c.update() call to encrypt something, and again, depending on the algorithm, you might do c.doFinal(). Each of these three methods are heavily overloaded to deal with the requirements of each encryption algorithm.
I don't have any encryption code to share, but if you do a search on the internet for something like Java DES example or Java MD5, you might get examples of code using java to perform DES or MD5 encryptions.
Good luck.
Jay Eckles
www.jayeckles.com
by tmanavalan
by tmanavalan
This discussion is closed to new replies.
Sort by Trending