用Java將文字轉成符合Linux下OpenLDAP的slappasswd指令的MD5與SHA編碼!
import java.security.*;
import sun.misc.*;
public class md5
{
public static void main(String args[]) throws NoSuchAlgorithmException
{
MessageDigest md = MessageDigest.getInstance("MD5");
//MessageDigest md = MessageDigest.getInstance("SHA-1");
String pw = "1234";
md.update(pw.getBytes());
byte[] digest = md.digest();
String base64str = new BASE64Encoder().encodeBuffer(digest);
System.out.println("MD5 = " + base64str);
}
}
全站熱搜
留言列表