请问 RSA 密钥对可以在 C#中使用私钥解密,但 openssl 无法使用私钥解密是怎么回事

2019-04-26 02:56:18 +08:00
 mingl0280
使用密钥对的公钥加密数据以后,如果将二进制数据放到 C#程序中使用私钥解密,是没有问题的,但是如果放到 openssl 中进行解密,则直接提示
140029040199320:error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag:tasn_dec.c:1217:
140029040199320:error:0D06C03A:asn1 encoding routines:ASN1_D2I_EX_PRIMITIVE:nested asn1 error:tasn_dec.c:785:
140029040199320:error:0D08303A:asn1 encoding routines:ASN1_TEMPLATE_NOEXP_D2I:nested asn1 error:tasn_dec.c:717:Field=n, Type=RSA
140029040199320:error:04093004:rsa routines:OLD_RSA_PRIV_DECODE:RSA lib:rsa_ameth.c:119:
140029040199320:error:0407B07B:rsa routines:RSA_check_key:d e not congruent to 1:rsa_chk.c:148:
140029040199320:error:0407B07C:rsa routines:RSA_check_key:dmp1 not congruent to d:rsa_chk.c:167:
140029040199320:error:0407B07D:rsa routines:RSA_check_key:dmq1 not congruent to d:rsa_chk.c:185:
140029040199320:error:0407B07E:rsa routines:RSA_check_key:iqmp not inverse of q:rsa_chk.c:196:
若使用 openssl 库进行解密,则提示
rsa_ossl_private_decrypt:padding check failed
有人遇到过这个问题吗?
3212 次点击
所在节点    信息安全
5 条回复
tomczhen
2019-04-26 03:07:25 +08:00
填充模式( padding ),向量( iv ),实现程序 /库默认行为可能有差异。
mingl0280
2019-04-26 05:38:21 +08:00
@tomczhen RSA 哪有 IV ……
不过之前问题应该是解决了,C#暴力写的 ASN1 文件估计是有 bug。
lzvezr
2019-04-26 09:45:22 +08:00
padding 错误不是填充的原因吗,一般使用标准填充和 0x00,不过前几天我遇到一个使用 0x20 的,搞的头疼
miaomiao0323
2019-04-26 11:12:04 +08:00
不同技术栈对密码算法的底层实现都有差异
mingl0280
2019-04-27 01:23:19 +08:00
@lzvezr 应该是 OpenSSL 的 padding 有鬼的锅……

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/558808

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX