Windows mobile 计算X509证书的密钥标识符

Windows mobile 计算X509证书的密钥标识符,windows-mobile,certificate,x509,Windows Mobile,Certificate,X509,我想计算X509证书的CERT\u KEY\u IDENTIFIER\u PROP\u ID,将其静默添加到Windows Mobile设备的注册表中(在转移期间)。截至,计算如下: SEQ[SEQ[rsa],key] 我猜密钥是cert.GetPublicKey(),但是rsa在这里意味着什么(我猜不是算法) 现在,我在网上搜索了三个小时,如果有人能给我指出正确的方向,我将非常高兴。为了阅读我需要写入注册表项的属性,我最终使用了以下CryptoAPI方法: [DllImport("crypt3

我想计算X509证书的
CERT\u KEY\u IDENTIFIER\u PROP\u ID
,将其静默添加到Windows Mobile设备的注册表中(在转移期间)。截至,计算如下:

SEQ[SEQ[rsa],key]

我猜
密钥
cert.GetPublicKey()
,但是
rsa
在这里意味着什么(我猜不是算法)


现在,我在网上搜索了三个小时,如果有人能给我指出正确的方向,我将非常高兴。

为了阅读我需要写入注册表项的属性,我最终使用了以下CryptoAPI方法:

[DllImport("crypt32.dll", SetLastError = true)]
private static extern IntPtr CertCreateCertificateContext(int dwCertEncodingType, byte[] pbCertEncoded, int cbCertEncoded);

[DllImport("crypt32.dll", SetLastError = true)]
private static extern bool CertFreeCertificateContext(IntPtr pCertContext);

[DllImport("crypt32.dll", SetLastError = true)]
private static extern bool CertGetCertificateContextProperty(IntPtr pCertContext, int dwPropId, IntPtr pvData, ref int pcbData);

private byte[] GetKeyIdentifier(X509Certificate certificate)
{
  var data = certificate.GetRawCertData();

  var context = CertCreateCertificateContext(1, data, data.Length);

  try
  {
    return ReadProperty(context, 0x14);
  }
  finally
  {
    CertFreeCertificateContext(context);
  }
}

private byte[] ReadProperty(IntPtr context, int property)
{
  var length = 0;

  // determine the ammount of memory to allocate for the data
  if (CertGetCertificateContextProperty(context, property, IntPtr.Zero, ref length))
  {
    var pointer = Marshal.AllocCoTaskMem(length);

    try
    {
      // query the property which is written to the allocated memory
      if (CertGetCertificateContextProperty(context, property, pointer, ref length) == false)
      {
        throw new InvalidOperationException(string.Format("Failed to query property {0}.", property));
      }

      // extract the data from the unmanaged memory
      var buffer = new byte[length];
      Marshal.Copy(pointer, buffer, 0, length);

      return buffer;
    }
    finally
    {
      Marshal.FreeCoTaskMem(pointer);
    }
  }
  else
  {
    throw new InvalidOperationException(string.Format("Failed to query property {0}.", property));
  }
}