Java for Python RSA

I am trying to encrypt a string from Java to Python using the Bouncy Castle J2ME library on the client side and Python M2Crypto on the other.

Everything is very good, I can decrypt it correctly, but the problem is in the supplement.

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 J2ME bouncy castle only provides: NoPadding OAEPWithAndPadding PKCS5Padding SSL3Padding

So, I can use NoPadding between both, but then the lines that are generated after decryption are filled with mixed characters.

I would really like to sort the contents, but I do not know how to convert between add-on schemes / if possible.

Please help me figure this out, this is killing me!

+3
source share
2 answers

I am not familiar with Bouncy Castle, but I think you are using something RSAEnginethat implements AsymmetricBlockCipher, so you should be able to use it PKCS1or not?

And there is also OAEPsupport that would give the correct parameters, should also work.

+1
source

Swamp lock provides upholstery. If you want, for example, to create RSA with the addition of PKCS1, you must 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;
}

This function will return the RSA engine with PKCS1Encoding.

+2
source

Source: https://habr.com/ru/post/1723746/


All Articles