Reputation: 9138
I have written a BlackBerry app that RSA encrypts a message using PKCS1FormatterEngine. This outputs a ciphered message formatted in PKCS #1 v2.1
Here is a snippet of the message:
ç½.¦B¯€ü6Áùε"aYÅÂ7;«&â/Ѥ²•¨S.°.b7<iÔ½Œ.:.Ý&D‹±ì‰8.V•.Ä$‡ZAÜ.p.Ø}åÜ.uK.Æøæ
I already have the RSA private key in .NET but I can't seem to find a way to decrypt this.
Any ideas on classes I should use etc would be greatly appreciated.
Upvotes: 2
Views: 1764
Reputation: 1
var encryptedtext = csp.Encrypt(plaintext, true); //Set OAEP=True
var decryptedtext = csp.Decrypt(plaintext, true); //Set OAEP=True
Upvotes: 0
Reputation: 9138
I'm using the RSACryptoServiceProvider .NET class with the function Decrypt.
The first paramater is the encrypted data and the second, a boolean specifies which padding type to use.
True = OAEP padding (PKCS#1 v2.1) False = PKCS#1 v1.5
It is strange because my code worked when it set it the parameter to false. I'm pretty sure the cipher is in PKCS#1 v2.1 because i'm using this class from the BlackBerry SDK.
Quote from the API document:
We implemented the PKCS1 formatter engine as per the PKCS #1 version 2.1 document.
In any case, it works for me now. Hope this helps somebody else. :)
Upvotes: 0
Reputation: 49677
PKCS#1 v2.1 has two encryption modes: RSAES-OAEP and RSAES-PKCS1-V1_5.
RSAES-PKCS1-V1_5 was also included in earlier versions of the standard, so it is often also called PKCS#1 v.1.5. It is therefore not uncommon to refer to RSAES-OAEP as PKCS#1 v.2.1 - but it is incorrect and errorprone.
In the documentation for PKCS1FormatterEngine, RIM documents that it has implemented PKCS#1 according to PKCS#1 v.2.1, but do not explain whether they mean RSAES-OAEP or RSAES-PKCS1-V1_5.
But since you report that RSACryptoServiceProvider.Decrypt(array, false);
works, I would conclude that they have implemented RSAES-PKCS1-V1_5. Just use that: it is the easiest way to decrypt RSAES-PKCS1-V1_5. Alternatively, you can use RSAPKCS1KeyExchangeDeformatter
.
Upvotes: 1
Reputation: 43553
Is there anything wrong with the standard RSAOAEPKeyExchangeDeformatter
class ? if so then you should show us your code.
It's been in the .NET framework forever but was not available before Windows XP (e.g. Windows 2000) IIRC - but that should not be a huge problem today.
Upvotes: 1
Reputation: 94038
Bouncy Castle seems to be able to use OAEP mode of RSA encryption/decryption. Never tried it though, I'm only using the Java libs of Bouncy.
Ah, found an example, see the sample code on the bottom of the page:
http://www.go4expert.com/forums/showthread.php?t=24827
Upvotes: 0