解码 OAEP 填充时出错

发布于 2024-07-23 08:05:31 字数 1402 浏览 5 评论 0原文

我的问题已经解决了一半..请帮助..

我已使用数字签名的公钥成功加密了文本,但在解密时出现错误。

解码 OAEP 填充时发生错误。

我的代码如下。

#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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文