I am new to cryptography and in over my head trying to sort it out on Windows, using C#.NET
I generated an elliptic curve P-256 (a.k.a. secp256r1 and prime256v1) key using the following command:
openssl ecparam –name prime256v1 -genkey –noout –out private.key
I generated a certificate signing request using the following command:
openssl req –new –key private.key –out certreq.csr –sha256
Another team sent me a base-64 encoded certificate in response. So far so good.
I have now received some "test" data that I need to compute the ECDSA signature of, using the private-key. The private key looks something like:
-----BEGIN EC PRIVATE KEY-----
FunnyHow?LIKEACLOWN?DOIAMUSEYOU?DOIMAKEYOULAUGH?==
-----END EC PRIVATE KEY-----
I have been struggling with code similar to the following so far:
byte[] cngBlob; // This was calculated based on another StackOverFlow post
byte[] testData = "JoePesciWasGreatInGoodfellas";
CngKey cngKey = CngKey.Import(cngBlob, CngKeyBlobFormat.EccPrivateBlob);
ECDsaCng eCDsaCng = new ECDsaCng(cngKey);
byte[] signatureECDSA = eCDsaCng.SignData(testData);
I tried calculating byte[] cngBlob
using the private-key file, based on Microsoft CNG | How to import PEM encoded ECDSA private key into MS Key Storage Provider
but however am not getting the correct answer in byte[] signatureECDSA
.
How do I read in the private key from the file and then use it to compute the ECDSA signature of the test data?
I have started to delve into the fascinating world of cryptography but it will take me some time to get familiar with it. Am I on the right track here? Any tips in the meantime to help me with this issue would be much appreciated.