public static string Sign(string contentForSign, string privateKey)
{
//Java->.Net的秘钥
var netKey = RSAKeyConvert.RSAPrivateKeyJava2DotNet(privateKey);
var rsa = new RSACryptoServiceProvider();
rsa.FromXmlString(netKey);
//创建一个空对象
var rsaClear = new RSACryptoServiceProvider();
var paras = rsa.ExportParameters(true);
rsaClear.ImportParameters(paras);
//签名返回
using (var sha256 = new SHA256CryptoServiceProvider())
{
var signData = rsa.SignData(Encoding.UTF8.GetBytes(contentForSign), sha256);
return Convert.ToBase64String(signData);//BytesToHex(signData);
}
}
/// <summary>
/// RSA私钥格式转换,java->.net