从专有名称中提取通用名

编程入门 行业动态 更新时间:2024-10-25 02:21:21
本文介绍了从专有名称中提取通用名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有没有在.NET中调用解析CN从RFC-2253连接codeD专有名称?我知道有一些第三方的库做到这一点,但我会preFER尽可能使用本地.NET库。

字符串的例子EN codeD DN

  

CN = L。鹰,O =苏\,Grabbit和银行经营,C = GB

     

CN =杰夫·史密斯,OU =销售额,DC = Fabrikam目录,DC = COM

解决方案

在.NET源$ C ​​$周围挖C中,它看起来像有一个内部实用工具类,可以的解析专有名称的到他们的不同组件。不幸的是,工具类是不公开的,但你可以使用反射来访问它:

字符串DN =CN = TestGroup,OU =组,OU = UT-SLC,OU = US,DC =公司,DC = COM; 装配dirsvc =的Assembly.Load(System.DirectoryServices中); 键入asmType = dirsvc.GetType(System.DirectoryServices.ActiveDirectory.Utils); MethodInfo的MI = asmType.GetMethod(GetDNComponents,BindingFlags.NonPublic可| BindingFlags.Static); 字符串[]参数= {DN}; VAR测试= mi.Invoke(NULL,参数); //test.Dump("test1");//shows使用Linqpad时,详细介绍 //转换专有名称(DN),以相对专有名称(RDN) MethodInfo的MI2 = asmType.GetMethod(GetRdnFromDN,BindingFlags.NonPublic可| BindingFlags.Static); VAR测试2 = mi2.Invoke(NULL,参数); //test2.Dump("test2");//shows使用Linqpad时,详细介绍

结果是这样的:

// test1的是内部的分量结构阵列上的名称/值作为字符串 名称值 CN TestGroup OU组 欧UT-SLC 欧美 DC公司 DC COM // test2的是一个字符串,CN = RDN CN = TestGroup

请不这是一个内部实用工具类,并在以后的版本可能会改变。

Is there a call in .NET that parses the CN from a rfc-2253 encoded distinguished name? I know there are some third-party libraries that do this, but I would prefer to use native .NET libraries if possible.

Examples of a string encoded DN

CN=L. Eagle,O=Sue\, Grabbit and Runn,C=GB

CN=Jeff Smith,OU=Sales,DC=Fabrikam,DC=COM

解决方案

After digging around in the .NET source code it looks like there is an internal utility class that can parse Distinguished Names into their different components. Unfortunately the utility class is not made public, but you can access it using reflection:

string dn = "CN=TestGroup,OU=Groups,OU=UT-SLC,OU=US,DC=Company,DC=com"; Assembly dirsvc = Assembly.Load("System.DirectoryServices"); Type asmType = dirsvc.GetType("System.DirectoryServices.ActiveDirectory.Utils"); MethodInfo mi = asmType.GetMethod("GetDNComponents", BindingFlags.NonPublic | BindingFlags.Static); string[] parameters = { dn }; var test = mi.Invoke(null, parameters); //test.Dump("test1");//shows details when using Linqpad //Convert Distinguished Name (DN) to Relative Distinguished Names (RDN) MethodInfo mi2 = asmType.GetMethod("GetRdnFromDN", BindingFlags.NonPublic | BindingFlags.Static); var test2 = mi2.Invoke(null, parameters); //test2.Dump("test2");//shows details when using Linqpad

The results would look like this:

//test1 is array of internal "Component" struct that has name/values as strings Name Value CN TestGroup OU Groups OU UT-SLC OU US DC company DC com //test2 is a string with CN=RDN CN=TestGroup

Please not this is an internal utility class and could change in a future release.

更多推荐

从专有名称中提取通用名

本文发布于:2023-10-23 01:56:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519396.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:名称

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!