开发者

Replace CAPICOM with .NET, validate certificate

开发者 https://www.devze.com 2022-12-29 23:18 出处:网络
My component is responsible for downloading files from the server. As part of file validation I have used CAPICOM (SignedCode object) to validate if a certificate contains a specific string and c开发者

My component is responsible for downloading files from the server. As part of file validation I have used CAPICOM (SignedCode object) to validate if a certificate contains a specific string and c开发者_开发百科all to Validate method of the SignedCode object. In case the file contains certificate without a requested string in the name, user was prompted if he trust this file.

Since CAPICOM going to be deprecated by Microsoft, I need to implement these logic using .NET libraries. How I can get the same functionality using .NET libraries? Is there any example on the web?

Thanks Zaky


using System.Security.Cryptography;

// ....

byte[] SignData(byte[] toSign)
{
    RSACryptoServiceProvider rsaCert =
            GetCertificateWithPrivateKeyFromSomewhere(); // this method is yours
    return rsaCert.SignData(toSign, new SHA1CryptoServiceProvider());
}

bool VerifyData(byte[] toVerify, byte[] signature)
{
    RSACryptoServiceProvider rsaCert =
            GetCertificateWithPublicKeyFromSomewhere(); // this method is yours
    return rsaCert.VerifyData(toVerify, new SHA1CryptoServiceProvider(), signature);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消