Java 到 Python RSA
我正在尝试使用客户端的 Bouncy Castle J2ME 库和另一端的 Python M2Crypto 将字符串从 Java 加密到 Python。
一切都很好,我可以正确解密,但填充是问题。
M2Crypto 库只给了我(据我所知)这些填充方案: 无填充= 3 pkcs1_padding = 1 sslv23_填充= 2 pkcs1_oaep_padding = 4
而充气城堡 J2ME 仅提供: 无填充 带和填充的 OAEP PKCS5填充 SSL3Padding
因此,我可以在两者之间使用 NoPadding,但是解密后生成的字符串会填充混乱的字符。
我真的很想解决填充问题,但我不知道如何在填充方案之间进行转换/如果可能的话。
请帮我解决这个问题,这简直要了我的命!
I'm trying to encrypt a string from Java to Python, using the library Bouncy Castle J2ME on the client side and Python M2Crypto on the other.
Everything is pretty good, I can decrypt it properly, but the padding is the issue.
The M2Crypto lib gives me (as far as I can tell) only these Padding schemes:
no_padding = 3
pkcs1_padding = 1
sslv23_padding = 2
pkcs1_oaep_padding = 4
While the bouncy castle J2ME only provides:
NoPadding
OAEPWithAndPadding
PKCS5Padding
SSL3Padding
So, I can use NoPadding between both, but then the strings that get generated after decryption are filled with jumbled characters.
I'd really like to get the padding sorted out, but I don't know how to convert between padding schemes / if that's even possible.
Please help me figure this out, it's killing me!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
充气城堡提供填充物。例如,如果您想要使用 PKCS1 填充创建 RSA,则必须执行以下操作:
该函数将返回一个具有 PKCS1Encoding 的 RSA 引擎。
Bouncy castle provides padding. If you want for example to make an RSA with PKCS1 padding you have to do this:
That function will return you an RSA engine with PKCS1Encoding.
我不熟悉 Bouncy Castle,但我猜你以某种方式使用
RSAEngine
实现AmetryBlockCipher
因此您应该能够使用PKCS1
是否?而且似乎还有
OAEP
支持,给定正确的参数也应该起作用。I'm not familiar with Bouncy Castle but I guess you somehow use
RSAEngine
which implementsAsymmetricBlockCipher
thus you should be able to usePKCS1
or not?And there also seems to be
OAEP
support, which given the right parameters should also work.