dongmie3987067 2016-05-20 20:05
浏览 317
已采纳

ldap密码属性的Golang utf16le编码

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

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"})

Thanks.

  • 写回答

1条回答 默认 最新

  • doulu2576 2016-05-20 21:06
    关注

    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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题