我正在尝试使用API,在发送之前,我需要使用SHA256WithRSA对值进行签名。但是现在我在根据API提供程序进行签名时遇到了错误。他说我的签错了。
这段代码适用于SHA256WithRSA还是SHA256?
我当前正在使用带有以下代码的bouncycastle。
public string Signature(string jsonstring, string Nonce)
{
//jsonobject + unix timestap + nounce
string ActualSigning = jsonstring + Nonce;
string privateKeyPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"C:\Program Files (x86)\GnuWin32\bin\key.pem");
var privateRsa = RsaProviderFromPrivateKeyInPemFile(privateKeyPath);
var signedData = privateRsa.SignData(Encoding.UTF8.GetBytes(ActualSigning), CryptoConfig.MapNameToOID("SHA256"));
return Convert.ToBase64String(signedData).ToLower();
}
private RSACryptoServiceProvider RsaProviderFromPrivateKeyInPemFile(string privateKeyPath)
{
//bouncycastle to read the file
using (TextReader privateKeyTextReader = new StringReader(File.ReadAllText(privateKeyPath)))
{
PemReader pr = new PemReader(privateKeyTextReader);
Asy`enter code here`mmetricCipherKeyPair keyPair = (AsymmetricCipherKeyPair)pr.ReadObject();
RSAParameters rsaParams = DotNetUtilities.ToRSAParameters((RsaPrivateCrtKeyParameters)keyPair.Private);
RSACryptoServiceProvider csp = new RSACryptoServiceProvider();
csp.ImportParameters(rsaParams);
return csp;
}
}