Hello,
Welcome to Microsoft Q&A!
In C# you can use the SignHash and VerifyHash methods of the RSACryptoServiceProvider class, which computes the signature for the specified hash value and verifies that a digital signature is valid. Here is an example of verify signature.
public static void VerifyLegacySignVerifyHash(bool useLegacySign, bool useLegacyVerify)
{
byte[] dataHash, signature;
using (HashAlgorithm hash = SHA256.Create())
{
dataHash = hash.ComputeHash(TestData.HelloBytes);
}
using (var rsa = new RSACryptoServiceProvider())
{
rsa.ImportParameters(TestData.RSA2048Params);
signature = useLegacySign ?
rsa.SignHash(dataHash, "SHA256") :
rsa.SignHash(dataHash, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
}
bool verified;
using (var rsa = new RSACryptoServiceProvider())
{
rsa.ImportParameters(
new RSAParameters
{
Modulus = TestData.RSA2048Params.Modulus,
Exponent = TestData.RSA2048Params.Exponent,
});
verified = useLegacyVerify ?
rsa.VerifyHash(dataHash, "SHA256", signature) :
rsa.VerifyHash(dataHash, signature, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
}
Assert.True(verified);
}
You can also load ncrypt.dll in c# by DllImport ,@Castorix31 already answered in your last question.
Thank you.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.