문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top