解码 OAEP 填充时出错
我的问题已经解决了一半..请帮助..
我已使用数字签名的公钥成功加密了文本,但在解密时出现错误。
解码 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论