Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I'm trying to compute the ECDSA signature of some data in C# (within a Unity project, using Bouncy Castle) using an existing private key (the private key having been generated using
openssl ecparam -name prime256v1 -genkey -noout -out eckey.pem
in terminal on macOS).
This is for the purpose of connecting to Apple's CloudKit as described under 'Authenticate Web Service Requests'
here
.
At the moment I'm trying with this, but the CreateKey fails with an IOException
extra data found after object
, thrown from Asn1Object.cs:24.
string privateKey = "<contents (within the BEGIN and END markers) of the privatekey.pem file I've previously generated>";
var key = PrivateKeyFactory.CreateKey(Encoding.UTF8.GetBytes(privateKey));
var data = Encoding.UTF8.GetBytes("some data here");
var signer = SignerUtilities.GetSigner("SHA256withECDSA");
signer.Init(true, key);
signer.BlockUpdate(data, 0, data.Length);
var signature = signer.GenerateSignature();
Debug.Log(signature);
I've tried keeping the newline characters in the private key string, as well as removing them - both give the same result.
Any assistance in loading the key correctly would be awesome, and then secondly how to correctly call GetSigner to get the correct EDCSA signer to generate the signature I need (as I'm sure SHA256withECDSA
is wrong, but I can't see in the source code what I should use).
Edit:
I've tried using PemReader and been able to load the private key. I'm now just trying to work out how to use the correct signer.
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.