import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import sun.misc.BASE64Encoder; public class SimpleMD5Example { public static String EncoderByMd5(String str) throws NoSuchAlgorithmException, UnsupportedEncodingException{ MessageDigest md5=MessageDigest.getInstance("MD5"); BASE64Encoder base64en = new BASE64Encoder(); String newstr=base64en.encode(md5.digest(str.getBytes("utf-8"))); return newstr; } public static void main(String[] args) throws UnsupportedEncodingException, NoSuchAlgorithmException { /* slappasswd -h {md5} -s "secret" {MD5}Xr4ilOzQ4PCOq3aQ0qbuaQ== */ String passwordToHash = "secret"; String N_md5=EncoderByMd5(passwordToHash); System.out.println(N_md5); /* slappasswd -h {md5} -s "dsideal4r5t6y7u" {MD5}yDL5JsEkVI9aVYfIW1pbPw== */ passwordToHash = "dsideal4r5t6y7u"; N_md5=EncoderByMd5(passwordToHash); System.out.println(N_md5); } }
Openldap的配置文件:
https://www.cnblogs.com/lijingcheng/p/4454802.html
时间: 2024-10-31 21:27:04