.NET使用OpenSSL生成的pem密钥文件(增加size为2048的密钥转换)(5)
//TestVerifyOATransferSign();
}
static string GetPemContent(string filePath)
{
string content = File.ReadAllText(filePath, Encoding.ASCII);
return content;
}
public static void TestSignAndEncrypt(string privateKey,string publicKey)
{
//sign
RSAParameters para = PemConverter.ConvertFromPemPrivateKey(privateKey);
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
rsa.ImportParameters(para);
byte[] testData = Encoding.UTF8.GetBytes("hello");
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
byte[] signData = rsa.SignData(testData, md5);
//verify
RSAParameters paraPub = PemConverter.ConvertFromPemPublicKey(publicKey);
RSACryptoServiceProvider rsaPub = new RSACryptoServiceProvider();
rsaPub.ImportParameters(paraPub);
if (rsaPub.VerifyData(testData, md5, signData))
{
Console.WriteLine("verify sign successful");
}
else
{
Console.WriteLine("verify sign failed");
}
//encrypt and decrypt data
byte[] encryptedData = rsaPub.Encrypt(testData, false);
相关新闻>>
- 发表评论
-
- 最新评论 更多>>