iso*_*tel 19 c# serial-number x509certificate
证书序列号是X509证书的唯一密钥吗?用户选择证书,程序将序列号存储在首选项中.以下代码是否会返回所选证书?
public static X509Certificate2 GetCertificateBySerialNumber(string serialNumber)
{
X509Certificate2 selectedCertificate = null;
X509Store store = null;
try
{
// get certificate from the store "My", "CurrentUser"
store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
X509Certificate2Collection allCertificates = (X509Certificate2Collection)store.Certificates;
X509Certificate2Collection foundCertificates = (X509Certificate2Collection)allCertificates.Find(X509FindType.FindBySerialNumber, serialNumber, false);
// select the first certificate in collection
foreach (X509Certificate2 certificate in foundCertificates)
{
selectedCertificate = certificate;
break;
}
}
finally
{
if (store != null)
{
store.Close();
}
}
return selectedCertificate;
}
Run Code Online (Sandbox Code Playgroud)
更新:我最终使用证书指纹,如jglouie所建议的那样.
jgl*_*uie 16
不可以.例如,OpenSSL让用户在创建证书时设置它.
请参阅:http://www.openssl.org/docs/apps/x509.html
-set_serial n指定要使用的序列号.此选项可与-signkey或-CA选项一起使用.如果与-CA选项一起使用,则不使用序列号文件(由-CAserial或-CAcreateserial选项指定).
序列号可以是十进制或十六进制(如果前面带有0x).也可以指定负序列号,但不建议使用它们.
Din*_*nei 12
TL;DR:您必须使用发行人名称 + 序列号的组合键。如果您需要一个简单的密钥,请使用证书的指纹。
从 security.stackexchange 引用 @ThomasPornin:
在证书中,序列号由颁发证书的 CA 选择。它只是写在证书上。CA 可以以任何它认为合适的方式选择序列号,不一定是随机的(它必须适合 20 个字节)。CA应该选择唯一的序列号,即对于 CA是唯一的。您不能指望序列号在全球范围内是唯一的;在 X.509 的梦想世界中,是全球唯一的 issuerDN+serial 对(每个 CA 都有自己唯一的专有名称,注意不要重复使用序列号)。
所述指纹是所计算的完整的证书,其中包括它的所有字段,包括签名过的散列值。对于给定的证书,该证书在全球范围内是独一无二的,取决于所使用的哈希函数的固有抗碰撞性。Microsoft 软件倾向于使用 SHA-1,已知其存在一些理论上的弱点,但尚未产生实际冲突(目前)。
来自:https : //security.stackexchange.com/questions/35691/what-is-the-difference-between-serial-number-and-thumbprint
Eug*_*its 10
如另一个答案所述,序列号在CA中必须是唯一的.因此,单独的序列号不能用作证书的唯一ID - 来自不同CA的证书可以具有相同的序列号.您需要存储Issuer和SerialNumber属性的组合.此外,对于自签名证书和自制CA软件,数字很可能会发生冲突,因为许多人将从0开始编号.
| 归档时间: |
|
| 查看次数: |
21773 次 |
| 最近记录: |