English 中文(简体)
Java to Python RSA
原标题:

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!

最佳回答

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.

问题回答

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.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签