且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C#使用RSA签名和验证签名.编码问题

更新时间:2022-04-11 07:26:55

您不能在已编码的消息上使用 ASCIIEncoding ,因为它包含无效ASCII字符的字节.存储编码消息的典型方法是在base64字符串中.

You cannot use ASCIIEncoding on the encoded message because it contains bytes which are invalid ASCII characters. The typical way you would store the encoded message is in a base64 string.

SignData 中,使用以下代码将字节数组编码为字符串:

In SignData, use the following to encode the byte array into a string:

return Convert.ToBase64String(signedBytes);

并在 VerifyData 中,使用以下代码将字符串解码回相同的字节数组:

and in VerifyData, use the following to decode the string back to the same byte array:

byte[] signedBytes = Convert.FromBase64String(signedMessage);