ldap密码属性的Golang utf16le编码 [英] Golang utf16le encoding for ldap password attribute

查看:170
本文介绍了ldap密码属性的Golang utf16le编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Go中的ldap重置MS Active Directory密码属性. AD在ldap.PasswordModifyRequest上不能很好地播放,所以我在使用ldap.NewModifyRequest. (使用gopkg.in/ldap.v2)

I'm trying to reset a MS Active Directory password attribute using ldap in Go. AD won't play nicely with ldap.PasswordModifyRequest so I'm using ldap.NewModifyRequest. (Using gopkg.in/ldap.v2)

AD将接受用引号和utf16le编码的密码,在Python中,我可以使用

AD will accept the password surrounded in quotes and utf16le encoded, in Python I can do this using

unicode_pass = unicode("\"secret\"", "iso-8859-1")
password_value = unicode_pass.encode("utf-16-le")
mod_attrs = [(ldap.MOD_REPLACE, "unicodePwd", [password_value])]
l.modify_s(user_dn, mod_attrs)

我该如何在Go中执行此操作?使用ldap.NewModifyRequestReplace我可以更改其他属性,但是我需要传递Request []string作为更新值,该值必须是我的编码密码,并且当我玩耍时遇到类型不匹配的情况与utf16.Encode ...

How can I do this in Go? Using ldap.NewModifyRequest and Replace I can change other attributes, but I need to pass Request []string for the updated value, that needs to be my encoded password, and I'm running into type mismatches when I play around with utf16.Encode...

modify := ldap.NewModifyRequest(dn)
modify.Replace("unicodePwd", []string{"encodedsecret"})

谢谢.

推荐答案

您可以使用

You can use the golang.org/x/text/encoding/unicode package to encode your string as UTF16.

使用此软件包,您可以编写如下内容:

Using this package you can write something like this:

utf16 := unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM)

encoded, err := utf16.NewEncoder().String("encodedsecret")

modify := ldap.NewModifyRequest(dn)
modify.Replace("unicodePwd", []string{encoded})

// do something with modify

这篇关于ldap密码属性的Golang utf16le编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆