例子:
byte[] raw = Encoding.Default.GetBytes("Hello, World!");
RSA key = RSA.Create();
for (int index = 0; index < 5; index++)
{
byte[] signed = key.SignData(raw, HashAlgorithmType.SHA256, RSASignaturePadding.Pkcs1);
string hashed = signed.ToSha256String();
Console.WriteLine(hashed);
}
输出结果:
043a718774c572bd8a25adbeb1bfcd5c0256ae11cecf9f9c3f925d0e52beaf89 043a718774c572bd8a25adbeb1bfcd5c0256ae11cecf9f9c3f925d0e52beaf89 043a718774c572bd8a25adbeb1bfcd5c0256ae11cecf9f9c3f925d0e52beaf89 043a718774c572bd8a25adbeb1bfcd5c0256ae11cecf9f9c3f925d0e52beaf89 043a718774c572bd8a25adbeb1bfcd5c0256ae11cecf9f9c3f925d0e52beaf89
现在考虑相同的代码,但使用ECDSA...
示例:
byte[] raw = Encoding.Default.GetBytes("Hello, World!");
ECDsa key = ECDsa.Create();
for (int index = 0; index < 5; index++)
{
byte[] signed = key.SignData(raw, HashAlgorithmType.SHA256);
string hashed = signed.ToSha256String();
Console.WriteLine(hashed);
}
输出:
043a718774c572bd8a25adbeb1bfcd5c0256ae11cecf9f9c3f925d0e52beaf89 a31fe9656fc8d3a459e623dc8204e6d0268f8df56d734dac3ca3262edb5db883 a871c47a7f48a12b38a994e48a9659fab5d6376f3dbce37559bcb617efe8662d d7ef0a04f3c8055644677299a9414a75adcb15916eb48417416c9317ace2ff4f 779f5dd63960abda52a7da70464b92eedd47f84a8dffda2d672e6a99de1bab95
RSA的签名输出与预期一致,但ECDSA的签名却不同。为什么相同数据的ECDSA签名会产生不同结果?