c# - System.Security.Cryptography.CryptographicException:'Cryptography_OAEPDecoding'
问题描述
我有一个程序必须使用 RSA privateKey 解密 3 个短语,但一直显示上面的异常 System.Security.Cryptography.CryptographicException: 'Cryptography_OAEPDecoding',我需要改变什么才能让它工作?,我试过看到其他页面,但它太混乱了,我最终添加了太多注释代码并重新开始。
解决方案
发生错误是因为您明确告诉 RSA 加密服务提供商使用OAEP 填充,但您的密码是使用 PKCS1 填充加密的。
// Your current statement:
var decryptedBytes = rsa.Decrypt(resultBytes, true);
第二个参数(fOAEP 记录如下:
// fOAEP:
// true to perform direct System.Security.Cryptography.RSA decryption using
// OAEP padding (only available on a computer running Microsoft Windows XP or
// later); otherwise, false to use PKCS#1 v1.5 padding.
因此,只需更改为 false;
var decryptedBytes = rsa.Decrypt(resultBytes, false);
我们得到以下输出:
INICIO DE LA SEGUNDA PARTE
M A N D A C O R R E O A J A V I E R B E L
C O N T U N O M B R E C O M P L E T O
Y L A F E C H A / H O R A
重要的旁注:
可能在复制/粘贴时,您的 base64 密码不正确。我纠正了他们这样的:
var FRASE1 = "IlmhPFKroDuK4AUtBGfaf5J6791DzMenkUBEXfRwZ7rmBHswHTf02LAba/Hs+rsh3wL6dpMQlEhlaIAVHaZZsw==";
var FRASE2 = "AMbsYR1pq9WYUj3mdqKvJj7tMznqBAcZLxM2C6WzNEUOqKD/qdEE76bNJPmYFKwVei2rhuHFsxh7nUzXmVKRdw==";
var FRASE3 = "J1jnq551phV+W4MVzE5caXIHqM3E0gz/t9PVtorqvDVqfne8CCF9UQiEk33Rssi1IEz6JH8Fd8ZAvnX3UWe5Vw==";
推荐阅读
- java - 我试图理解为什么 notifyAll() 没有在共享锁上醒来
- c# - 动态改变 TargetName DoubleAnimation c# xaml
- node.js - tsconfig 中的路径无法导入类型
- database - MongoDB 聚合具有各个日期范围的子字段
- python - Python:删除标准差小于 25% 的列
- python - 将数据库值转换为表单时出错
- git - 在团队基础服务器上打开文件时出现“不正确的功能”错误
- python - 使用 Django 和 SMTP 协议发送电子邮件时出现 TimeoutError 错误
- python - 为什么 sqlite 3 停止在我的代码中处理“删除”类调用?
- jenkins - Jenkins 中的 CloudBees Docker Hub/注册表通知插件错误