码迷,mamicode.com
首页 > 编程语言 > 详细

SimpleMD5Example (OpenLdap加密MD5算法的JAVA实现)

时间:2017-11-24 22:48:24      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:md5   href   log   bsp   html   word   lap   ide   import   

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实现)

标签:md5   href   log   bsp   html   word   lap   ide   import   

原文地址:http://www.cnblogs.com/littlehb/p/7892349.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!