package hash; import java.security.*; public class Encryption { public static String md5(String plainText) { String encryptedText = ""; try { MessageDigest md = MessageDigest.getInstance("MD5"); byte[] encryptedData = md.digest(plainText.getBytes()); encryptedText = new String(encryptedData); } catch (NoSuchAlgorithmException ex) { } return encryptedText; } }
Out put String : ,¹b¬Y [–K -#Kp
package hash; public class Main { public static void main(String[] args) { System.out.println(Encryption.md5("123")); } }
package hash; import java.security.*; public class Encrypt { public static String md5(String plainText) { String encryptedText = ""; try { MessageDigest md = MessageDigest.getInstance("MD5"); byte encryptedData[] = md.digest(plainText.getBytes()); StringBuffer hexString = new StringBuffer(); for (int i = 0; i < encryptedData.length; i++) { String hex = Integer.toHexString(0xFF & encryptedData[i]); if (hex.length() == 1) { hexString.append('0'); } hexString.append(hex); } encryptedText = hexString.toString(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return encryptedText; } }
package hash; public class Main { public static void main(String[] args) { System.out.println(Encrypt.md5("123")); } }
Out put string : 202cb962ac59075b964b07152d234b70
Thanks Sameera,
ReplyDeletethe code of Password Encryption work fine for me..
Can u also give the code for Password decryption also...
Thanks so much...
MD5 like password hashing algorithms are one way algorithms. There are no ways to decrypt those.
DeleteThanks for reply..
DeleteSo please tell me the two way encryption/decryption code...
And please give me some information about SALT algorithm.
And tell me, what is the use of one way algorithm if we doesn't get the same result after decryption.
DeleteWe use one-way algorithems to hash passwords before saving to database.
DeleteWhen user submit the login form we,
get the palin password
hash it
compare hash with the hash in database
if match user can login
if sombody hack the database he cannot get user passwords.Because we don't save plian text passwords in database.
Thanks its very use full
ReplyDeleteHi, can you help me to gain a better approach to hacking? I'm a newcomer & I would like to learn some useful skills.
ReplyDeleteMany thanks. Reece
thanxs dude it is very usefull
ReplyDeletecan u tell me how to do encrypt and decrypt using struts with hibernate. how can we connect in same generator key. i tried but it showing other other names
ReplyDeletedear sir, can you give the code for comparing hash with the hash in database.
ReplyDeleteAs i want to save encrypted password to database then on login compare hash with the hash in database if matches user can login.