SimpleMD5Example (OpenLdap加密MD5算法的JAVA实现)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SimpleMD5Example (OpenLdap加密MD5算法的JAVA实现)相关的知识,希望对你有一定的参考价值。
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
以上是关于SimpleMD5Example (OpenLdap加密MD5算法的JAVA实现)的主要内容,如果未能解决你的问题,请参考以下文章