RSA sign using SHA256 hash algorithm

Viewed 75

I want to use RSA sign with SHA256.

Specification from client: RSASSA PSS shall follow PKCS#1 v2.2 (see RFC 8017 2016).

Hash: SHA 256,
MGF: MGF1 (refer to chapter B2.1 in PKCS#1, Hash = SHA 256),
sLen = 32,
K = d (the RSA private exponent) and n (the RSA modulus),
M = SecretSeed,
S = SecurityKey (parameter specific to the signature verification operation).

I tried:

RSA rsa = new RSACng();
rsa.ImportParameters(rsaParams);
rsa.SignData(bytesToSign, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);

also with

var rsa = new RSACryptoServiceProvider(2048);
rsa.ImportParameters(rsaParams);
var rsaValue = rsa.SignData(bytesToSign,"SHA256");

Private key and public key are ok because I decrypt the bytes received from client and are matching with what client has before encryption. Method to decrypt I use to decrypt and is working:

RSA rsa = new RSACng();
rsa.ImportParameters(rsaParams);
rsa.Decrypt(bytesRnmToDecrypt, RSAEncryptionPadding.OaepSHA256);

My problem is that I need to sign these bytes before sending back to the client and these 256 bytes output (from methods that I used above) are not ok for the client. I think I'm not using the right method to sign or I'm missing a parameter

0 Answers
Related