package com.java.discussions101;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import sun.misc.BASE64Encoder;
public class Encryptor {
public static void main(String args[]){
String password="discussions101";
MessageDigest md = null;
try{
md = MessageDigest.getInstance("SHA");
}catch(NoSuchAlgorithmException e){
e.printStackTrace();
}
try{
md.update(password.getBytes("UTF-8"));
}catch(UnsupportedEncodingException e){
e.printStackTrace();
}
byte raw[] = md.digest();
String hash = (new BASE64Encoder()).encode(raw);
System.out.println("Encrypted Password is : "+hash);
}
}
The Output is : "Encrypted Password is : yCYUi6yitVBINR/HKKdIj47alYM="
This program can be used for password authentication in user verification or in many purposes. Another good thing about this technique is that you can not get the original password back in form after encryption is done.
You may try the program backwards to check it out.
Cheers.....
Cheers.....
No comments:
Post a Comment