JAVA RSA Encryption and C# MSCAPI RSA Decryption
<p>We have our RSA Private key stored in smartcard. The key cannot be exported out. The encryption of data is being done as described in below code snippet. </p>

<pre><code>public byte[] RsaEncrypt(PublicKey publicKey, byte[] data, byte[] pSource)
{
Cipher rsaCipher = Cipher.getInstance("RSA/ECB/OAEPWITHSHA-256ANDMGF1PADDING",
                "BC");
PSource pSrc = (new PSource.PSpecified(pSource));
rsaCipher.init(Cipher.ENCRYPT_MODE, publicKey,
                new OAEPParameterSpec("SHA-256", MGF1,
                        MGF1ParameterSpec.SHA256, pSrc));
return rsaCipher.doFinal(data);
}
</code></pre>

<p>How to decrypt the encrypted data in C#? We can use the smartcard private key using MSCAPI by below code snippet.</p>

<pre><code>public byte[] RsaDecrypt(byte[] encryptedData, bool fOAEP)
{
CspParameters cspParams = new CspParameters(0x01, "SafeSign Standard Cryptographic Service Provider");
SecureString keyPassword = new SecureString();
char[] ContainerPassword = "1234".ToCharArray();
for (int i = 0; i &lt; ContainerPassword.Length; i++)
    keyPassword.AppendChar(ContainerPassword[i]);
cspParams.KeyPassword = keyPassword;
RSACryptoServiceProvider RsaProvider = new RSACryptoServiceProvider(cspParams);

RsaProvider.Decrypt(data, fOAEP);
}
</code></pre>

<p>Both with fOAEP set true and false, we are not able decrypt the data.</p>
