Java 到 Python RSA

发布于 2024-08-12 15:29:38 字数 398 浏览 4 评论 0原文

我正在尝试使用客户端的 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 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

难理解 2024-08-19 15:29:38

充气城堡提供填充物。例如,如果您想要使用 PKCS1 填充创建 RSA,则必须执行以下操作:

public static PKCS1Encoding create_rsa_public(RSAKeyParameters PublicKey){
    RSAEngine engine=new RSAEngine();
    PKCS1Encoding encrypto=new PKCS1Encoding(engine);
    encrypto.init(true,PublicKey);
    return encrypto;
}

该函数将返回一个具有 PKCS1Encoding 的 RSA 引擎。

Bouncy castle provides padding. If you want for example to make an RSA with PKCS1 padding you have to do this:

public static PKCS1Encoding create_rsa_public(RSAKeyParameters PublicKey){
    RSAEngine engine=new RSAEngine();
    PKCS1Encoding encrypto=new PKCS1Encoding(engine);
    encrypto.init(true,PublicKey);
    return encrypto;
}

That function will return you an RSA engine with PKCS1Encoding.

你又不是我 2024-08-19 15:29:38

我不熟悉 Bouncy Castle,但我猜你以某种方式使用 RSAEngine 实现 AmetryBlockCipher 因此您应该能够使用 PKCS1 是否?

而且似乎还有 OAEP 支持,给定正确的参数也应该起作用。

I'm not familiar with Bouncy Castle but I guess you somehow use RSAEngine which implements AsymmetricBlockCipher thus you should be able to use PKCS1 or not?

And there also seems to be OAEP support, which given the right parameters should also work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文