Problem porting RSAPKCS1SignatureFormatter implementation to RSA.Create()
Hi
I am trying to port an oauth1.0 implementation using RSAPKCS1SignatureFormatter to dotnet core.
This is what I have so far
original net40
private byte[] SignByte(SHA1CryptoServiceProvider hash)
{
var formatter = new RSAPKCS1SignatureFormatter(myX509Certificate2.PrivateKey);
formatter.SetHashAlgorithm("MD5");
return formatter.CreateSignature(hash);
}
port netcoreapp1.0
private byte[] SignByte(byte[] hash)
{
byte[] signature = RSA.Create().SignHash(hash, HashAlgorithmName.MD5, RSASignaturePadding.Pkcs1);
return signature;
}
However I keep getting this exception when trying to use MD5 with RSASignaturePadding.Pkcs1
An unhandled exception of type 'Internal.Cryptography.CryptoThrowHelper.WindowsCryptographicException' occurred in System.Security.Cryptography.Algorithms.dll
Additional information: The parameter is incorrect
Any ideas?
Also how would I import the key when using RSA.Create()?
Thanks
@TrplM You can import a key from an RSAParameters by using the ImportParameters method on RSA.
Your code, aside from not using the RSA object in a using statement (and loading the key you want) seems correct, provided that hash is an array of the correct size (16 bytes for MD5). If the array is the correct length, perhaps a full callstack can help reveal what's gone wrong.
Since we haven't heard anything in quite a while I'm going to close this issue. Feel free to post a followup, since that'll still send out notifications.