3

I am half way through my problem.. Please Help..

I have successfully encrypted the text using public key of digital signatures but while decrypting it, I am getting the error.

Error occurred while decoding OAEP padding.

My code is a follows.

#region Test Encryption
public void a()
{
    using (var rsa = new RSACryptoServiceProvider())
    {
        // This String consists only Public Key Information 
        String publicKeyOnly = rsa.ToXmlString(false);

        // This String consists both Private/Public Key information 
        String publicPrivate = rsa.ToXmlString(true);
    }
}

//encrypt 
public byte[] b(String publicKeyOnly)
{
    byte[] encryptedData;

    using (var rsaPublicOnly = new RSACryptoServiceProvider())
    {
        rsaPublicOnly.FromXmlString(publicKeyOnly);
        encryptedData = rsaPublicOnly.Encrypt(
        Encoding.UTF8.GetBytes("This String is to be Secured."), true);
    }

    return encryptedData;
}

//Decrypt 
public String c(byte[] encryptedData)
{
    String decryptedPassword;

    using (var rsaPublicPrivate = new RSACryptoServiceProvider())
    {
        RSACryptoServiceProvider.UseMachineKeyStore = true;

        // Providing Private key information to RSA Object 
        rsaPublicPrivate.FromXmlString(_PrivateKeyXML);

        // Decrypting the encrypted data by using RSA object "rsaPublicPrivate" 
        decryptedPassword = rsaPublicPrivate.Decrypt(encryptedData, true).ToString();
    }

    return decryptedPassword;
}
#endregion
Fabiano
  • 5,001
  • 2
  • 28
  • 31
Meetu Choudhary
  • 1,373
  • 4
  • 14
  • 26
  • Hi, Did you ever get an answer to this? I now have the same problem! – Ben Feb 01 '13 at 11:45
  • 6
    possible duplicate of [Error occurred while decoding OAEP padding](http://stackoverflow.com/questions/954416/error-occurred-while-decoding-oaep-padding) – fjsj May 08 '15 at 02:13

0 Answers0