简体   繁体   中英

RSACryptoServiceProvider decrypting with ECB and MGF1 padding

I'm using RSACryptoServiceProvider from System.Security.Cryptography package. I need to decrypt some input coming from Android application using my private key. It's encrypting it in Java code with RSA/ECB/OAEPWithSHA256AndMGF1Padding algorithm.
The problem is I cannot find any way to set nither padding MGFT1 nor ECB . Could you help me somehow? Are these settings default or should I use another library? It's hard to believe it's impossible.

Crucial part of my code goes here:

RSAParameters RSAParamPrivateKey = DotNetUtilities.ToRSAParameters(privateKey)
RSACryptoServiceProvider csp = new RSACryptoServiceProvider();
csp.ImportParameters(RSAParamPrivateKey);

return csp.Decrypt(encryptedAESKey, RSAEncryptionPadding.OaepSHA256);

The "ECB" is (hopefully) meaningless. RSA should only ever be used for a one block of data.

MGF1 is the only standard defined MGF, so it's not an option that .NET lets you currently specify.

OAEP with an algorithm other than SHA-1 is beyond RSACryptoServiceProvider 's capabilities. But RSACng can do it:

RSAParameters RSAParamPrivateKey = DotNetUtilities.ToRSAParameters(privateKey);
RSA rsa = new RSACng();
rsa.ImportParameters(RSAParamPrivateKey);

return rsa.Decrypt(encryptedAESKey, RSAEncryptionPadding.OaepSHA256);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM