Last active
November 8, 2023 15:41
-
-
Save lamngockhuong/f144f67d037d7d91e8b2930fe129cd09 to your computer and use it in GitHub Desktop.
[Mã hóa MD5 trong Java] #java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.math.BigInteger; | |
import java.security.MessageDigest; | |
import java.security.NoSuchAlgorithmException; | |
/** | |
* Author: Lam Ngoc Khuong | |
* Website: http://ngockhuong.com - Programming knowledge sharing | |
*/ | |
public class MD5 { | |
public String md5(String str){ | |
MessageDigest md; | |
String result = ""; | |
try { | |
md = MessageDigest.getInstance("MD5"); | |
md.update(str.getBytes()); | |
BigInteger bi = new BigInteger(1, md.digest()); | |
result = bi.toString(16); | |
} catch (NoSuchAlgorithmException e) { | |
e.printStackTrace(); | |
} | |
return result; | |
} | |
public static void main(String[] args) { | |
MD5 lib = new MD5(); | |
String password = "123456"; | |
String strmd5 = lib.md5(password); | |
System.out.println("Sau khi mã hóa: "+strmd5); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment