简体   繁体   English

如何在不使用第三方库的情况下从C#的证书吊销列表中提取序列号列表?

[英]How do I extract the list of serial numbers from a Certificate Revocation List in C# without using third party libraries?

I've connected to a MS PKI Certificate Revocation List distribution point and obtained the CRL 我已连接到MS PKI证书吊销列表分发点,并获得了CRL

What's the most straightforward way to extract the list of serial numbers from the CRL without using third party libraries? 不使用第三方库从CRL中提取序列号列表的最直接方法是什么?

You will have to unroll the CRL by using unmanaged CryptoAPI functions (through p/invoke, of course). 您将必须使用非托管的CryptoAPI函数(当然是通过p / invoke)来展开CRL。 Generally, you will have to the following high-level step-by-step: 通常,您将必须执行以下高级操作:

  1. CertCreateCRLContext -- this function will return a pointer to a CRL_CONTEXT structure. CertCreateCRLContext-此函数将返回一个指向CRL_CONTEXT结构的指针。
  2. Use Marshal.PtrToStructure .NET method to convert pCrlInfo pointer of CRL_CONTEXT structure to CRL_INFO structure. 使用Marshal.PtrToStructure .NET方法将CRL_CONTEXT结构的pCrlInfo指针转换为CRL_INFO结构。
  3. rgCRLEntry is an array of pointers (array size is determined by cCRLEntry member of CRL_INFO ). rgCRLEntry是一个指针数组(数组大小由下式确定cCRLEntry的构件CRL_INFO )。
  4. Iterate over this array by incrementing starting pointer by the size of CRL_ENTRY structure. 通过将起始指针增加CRL_ENTRY结构的大小来循环访问此数组。
  5. SerialNumber member of CRL_ENTRY is a byte array. CRL_ENTRY SerialNumber成员是一个字节数组。 You can directly use Marshal.Copy(IntPtr, Byte[], Int32, Int32) method to copy unmanaged array to managed. 您可以直接使用Marshal.Copy(IntPtr, Byte[], Int32, Int32)方法将非托管数组复制到托管。 This will give you serial number. 这将为您提供序列号。 Repeat steps 4-5 for each CRL entry. 对每个CRL条目重复步骤4-5。

Do not forget to release pointer to CRL_CONTEXT structure by calling CertFreeCRLContext function when finished to prevent memory leaks. 完成操作以防止内存泄漏时,请不要忘记通过调用CertFreeCRLContext函数来释放指向CRL_CONTEXT结构的指针。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 证书吊销列表c# - Certificate Revocation List c# 如何在不使用第三方库的情况下从HTML提取文本? - How I can extract text from HTML without using third-party libraries? 以编程方式安装证书吊销列表 C# - Programmatically installing certificate revocation list C# C#BouncyCastle-如何为该证书创建sha512ECDSA证书和有效的证书吊销列表? - C# BouncyCastle-How can I create a sha512ECDSA certificate and a valid certificate revocation list for this certificate? 没有第三方库的文本解析应用程序c# - text parsing application c# without third party libraries Svg 到 base64 没有第三方库 c# - Svg to base64 without third party libraries c# 如何使用EventReceiver从c#中的SharePoint列表中提取DateTime值? - How do i extract DateTime values from SharePoint list in c# using EventReceiver? c#如何查看证书吊销状态? - How to check certificate revocation status in c#? 我们如何仅使用C#而不使用任何第三方工具来进行UI自动化测试? - How can we do UI automation testing only using C# without any third party tool? 在C#中,我如何通过SSH2使用FTP,最好没有第三方代码 - In c# how do I use FTP over SSH2, preferably without third party code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM