Escaping non special characters in string for LDAP query

ぃ、小莉子 提交于 2019-12-05 09:50:53

Escape invalid characters in a distinguished name is done with a leading slash ('\'). For example, the distinguished name above should be:

"CN=Surname\, Lastname,OU=Users,DC=Foo,DC=net"

According to section 2.4 of RFC 4514: Lightweight Directory Access Protocol (LDAP): String Representation of Distinguished Names, the characters , ", #, +, ,, ;, <, =, >, and \ can be escaped by a leading slash. Other non-alphanumeric characters should be shown in the form of \XX where XX are the hex digits of the UTF8 character encoding. See section 4 for examples.

Note that the X500DistinguishedName class (in System.Security Cryptography) does not appear to have a Parse or Escape method to help in this situation.

Certain characters must be escaped with a backslash (\) followed by two hex digits, not a single backslash according to RFC4514. Many directory directory server support the \,, but since it is not standardized, LDAP clients must not use this notation - it would work on some servers but not others and clients must not assume they are communicating with a particular servers' software.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!