I have a public key and signature generated in Java which I would like to verify in C# using ECDsaCng. The public key is MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAExeg15CVOUcspdO
The cause is a different format. Microsoft expects the format r|s
while your signature is specified in the ASN.1
-format (which is explained in the context of ECDSA here):
0x30|b1|0x02|b2|r|0x02|b3|s
b1 = Length of remaining data
b2 = Length of r
b3 = Length of s
Your signature
30440220534465047322bbebe9db49e23e073fc9d71d2b6cdf0deab11b7c7055c168e1800220093bf123cc266534b412bca0629d51df4af4c49a8af475cdd85fb14f3279d80a
can be separated in the following portions
30 44 02 20 534465047322bbebe9db49e23e073fc9d71d2b6cdf0deab11b7c7055c168e180 02 20 093bf123cc266534b412bca0629d51df4af4c49a8af475cdd85fb14f3279d80a
so that the individual portions can be easily identified:
b1 = 0x44
b2 = 0x20
r = 0x534465047322bbebe9db49e23e073fc9d71d2b6cdf0deab11b7c7055c168e180
b3 = 0x20
s = 0x093bf123cc266534b412bca0629d51df4af4c49a8af475cdd85fb14f3279d80a
Thus
r|s = 534465047322bbebe9db49e23e073fc9d71d2b6cdf0deab11b7c7055c168e180093bf123cc266534b412bca0629d51df4af4c49a8af475cdd85fb14f3279d80a
If you run your code using this format, verification is successful.