|
|
using System.Security.Cryptography;
|
|
|
using com.hitrust.b2b.trustpay.client;
|
|
|
using System;
|
|
|
using System.Text;
|
|
|
using System.Security.Cryptography.X509Certificates;
|
|
|
|
|
|
namespace com.hitrust.b2b.Security
|
|
|
{
|
|
|
public class Signature
|
|
|
{
|
|
|
public int verifySignature(string aCertFile, string aMessage, string aBase64Signature)
|
|
|
{
|
|
|
X509Certificate certificate;
|
|
|
int num = 0;
|
|
|
try {
|
|
|
certificate = X509Certificate.CreateFromCertFile(aCertFile);
|
|
|
byte[] rgbSignature = new Base64().decode(aBase64Signature);
|
|
|
byte[] rgbHash = new SHA1Managed().ComputeHash(Encoding.GetEncoding("UTF-8").GetBytes(aMessage));
|
|
|
|
|
|
//certificate.PublicKey.ExportParameters(false);
|
|
|
RSACryptoServiceProvider publicKey = new RSACryptoServiceProvider();
|
|
|
publicKey.ImportParameters(new RSAParameters() { Exponent = certificate.GetPublicKey() });
|
|
|
if (!publicKey.VerifyHash(rgbHash, CryptoConfig.MapNameToOID("SHA1"), rgbSignature)) {
|
|
|
num = -1;
|
|
|
}
|
|
|
} catch (Exception exception) {
|
|
|
SupportClass.WriteStackTrace(exception, Console.Out);
|
|
|
num = 1;
|
|
|
}
|
|
|
return num;
|
|
|
}
|
|
|
}
|
|
|
}
|