I am trying to sign a string with a PKCS#8 key using SHA-256 with RSA.
The RSACng.SignData()
method requires a RSASignaturePadding, of which the options are Pkcs1
and Pss
. I can't find anything definitive to tell me which would be used for PKCS#8.
// Decode Token (token is Base64 & PKCS8 encoded)
byte[] decodedKey = Convert.FromBase64String(myBase64String);
CngKey key = CngKey.Import(decodedKey, CngKeyBlobFormat.Pkcs8PrivateBlob);
// Build signature
string signature = "123abc";
byte[] bytes = Encoding.UTF8.GetBytes(signature);
// Sign signature using key & SHA256 w RSA
var unsigned = new RSACng(key);
byte[] data = unsigned.SignData(bytes, HashAlgorithmName.SHA256, <??????>);
Cryptography is all new to me, so if my approach is way off, please let me know.