【发布时间】:2019-02-25 08:47:55
【问题描述】:
我正在使用C# 编写一个数字签名程序,并使用RSACryptoServiceProvider 类根据文件生成公钥和私钥以及签名。如果在程序中,我用公钥、签名和文件检查签名,它可以正常工作,但是如果我将我的密钥保存为文件中的任何格式,换句话说,我将更改它们的格式并返回到第一个状态它不起作用。因为我不能把它正确地变成RSAParameters。请指导我?
显示变化的简单示例测试:
var publicParams = rsaWrite.ExportParameters(false); // Generate the public key.
var testpublicParams = publicParams;
string st = Encoding.ASCII.GetString(publicParams.Modulus);
testpublicParams.Modulus = Encoding.ASCII.GetBytes(st);
if(publicParams.Modulus != testpublicParams.Modulus) {
Console.WriteLine("The key has been changed.");
}
【问题讨论】:
-
您必须对整个
RSAParameters对象进行反序列化/序列化才能加载保存。最简单的是 NewtonsoftJsonConvert。 -
有没有机会使用PemUtils 来代替?
-
@huysentruitw 听起来不错,谢谢。
-
@Oliver 我会看到的,谢谢。
标签: c# digital-signature rsacryptoserviceprovider