You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
package LdapUtil
import (
"crypto/md5"
"encoding/base64"
"fmt"
"io"
"strconv"
)
func Hex2Dec ( val string ) int {
n , err := strconv . ParseUint ( val , 16 , 32 )
if err != nil {
fmt . Println ( err )
}
return int ( n )
}
/**
功能: 获取通过ldap加密后的密码
作者:黄海
时间: 2020-04-27
*/
func GetLdapPassword ( md5pass string ) string {
//1、计算md5
w := md5 . New ( )
io . WriteString ( w , md5pass )
md5pass = fmt . Sprintf ( "%x" , w . Sum ( nil ) )
//2、字节数组
var baKeyword = make ( [ ] byte , len ( md5pass ) / 2 )
for i := 0 ; i < len ( baKeyword ) ; i ++ {
//十六进制字符串转整数
c := Hex2Dec ( md5pass [ i * 2 : i * 2 + 2 ] )
d := 0xff & c
baKeyword [ i ] = byte ( d ) //整数强制转为字节
}
encodeString := base64 . StdEncoding . EncodeToString ( baKeyword )
return encodeString
}