Consider the following code using RSA...
Example:
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);
}
Output:
043a718774c572bd8a25adbeb1bfcd5c0256ae11cecf9f9c3f925d0e52beaf89 043a718774c572bd8a25adbeb1bfcd5c0256ae11cecf9f9c3f925d0e52beaf89 043a718774c572bd8a25adbeb1bfcd5c0256ae11cecf9f9c3f925d0e52beaf89 043a718774c572bd8a25adbeb1bfcd5c0256ae11cecf9f9c3f925d0e52beaf89 043a718774c572bd8a25adbeb1bfcd5c0256ae11cecf9f9c3f925d0e52beaf89
Now consider the same code, except using ECDSA...
Example:
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);
}
Output:
043a718774c572bd8a25adbeb1bfcd5c0256ae11cecf9f9c3f925d0e52beaf89 a31fe9656fc8d3a459e623dc8204e6d0268f8df56d734dac3ca3262edb5db883 a871c47a7f48a12b38a994e48a9659fab5d6376f3dbce37559bcb617efe8662d d7ef0a04f3c8055644677299a9414a75adcb15916eb48417416c9317ace2ff4f 779f5dd63960abda52a7da70464b92eedd47f84a8dffda2d672e6a99de1bab95
RSA's signature output I expected; ECDSA's, I didnt. Why does ECDSA produce different signatures for the same data?