【发布时间】:2009-06-19 09:12:35
【问题描述】:
我有一个小问题。我想验证证书的完整性。
所以我做了这段代码:
using System.Security.Cryptography;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
SHA1Managed sha1 = new SHA1Managed();
RSACryptoServiceProvider csp = null;
AsymmetricAlgorithm rsaAlgo = certificatEnCours.PublicKey.Key;
byte[] data = null;
byte[] hash = null;
string keyPublic = "";
string signatureLikeInteger = "";
bool verif = false;
// ------------- PART 1 -------------
signatureLikeInteger = certificatEnCours.Thumbprint;
data = Convert.FromBase64String(signatureLikeInteger);
// ------------- PART 2 -------------
hash = sha1.ComputeHash(certificatEnCours.RawData);
keyPublic = rsaAlgo.ToXmlString(false);
csp = new RSACryptoServiceProvider();
csp.FromXmlString(keyPublic);
// ------------------------------
verif = csp.VerifyData(hash, CryptoConfig.MapNameToOID("SHA1"), data);
我的问题是我的变量“verif”上已经有了值“false”。
【问题讨论】:
-
有人可以重新格式化问题。阅读起来非常困难。
标签: c# certificate sha1 verify rsacryptoserviceprovider