如何获得证书的SHA-256指纹?
沙-256证书有两个拇指指纹,我可以检索主拇指指纹,但不能检索SHA-256。
发布于 2016-01-07 03:58:45
使用:
public static String GetSha2Thumbprint(X509Certificate2 cert)
{
Byte[] hashBytes;
using (var hasher = new SHA256Managed())
{
hashBytes = hasher.ComputeHash(cert.RawData);
}
string result = BitConverter.ToString(hashBytes)
// This will remove all the dashes in between each two characters
.Replace("-", string.Empty).ToLower();
return result;
}在获得哈希字节之后,您必须进行位转换。
这篇文章也帮助了我:https://stackoverflow.com/questions/11477083/hashing-text-with-sha-256-at-windows-forms
发布于 2016-01-05 06:26:44
如果您想获得证书的SHA-256指纹,您必须做一些手工工作。内置的拇指纹属性仅限于沙一。
您必须使用沙256级并计算证书内容的哈希:
using System;
using System.Linq;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
namespace MyNamespace {
class MyClass {
public static String GetSha2Thumbprint(X509Certificate2 cert) {
Byte[] hashBytes;
using (var hasher = new SHA256Managed()) {
hashBytes = hasher.ComputeHash(cert.RawData);
}
return hashBytes.Aggregate(String.Empty, (str, hashByte) => str + hashByte.ToString("x2"));
}
}
}并在必要时将此代码转换为扩展方法。
https://stackoverflow.com/questions/34586588
复制相似问题