RSA encryption in Java: cross platform issues?

situation

I am using RSA encryption in Java I am loading the data on HTC saphire (32b) developer's mobile phone with Android 2.2 equipped with CyanogenMod, and then decrypting the data on a 64 bit server running Mandriva Linux 2010 I use the same public key and private key pair on both machines, which can correctly encrypt / decrypt the data on Android phones and Linux servers, but I can't encrypt the data on mobile phones and then decrypt it on the server I got a bad fill exception I have confirmed that the data is sent correctly through the phone and the server is parsing correctly Therefore, I can't figure out why the decryption failed Who can help me with this? Perhaps the RSA algorithm in Java has some basic assumptions about word size?

More information:

>My encryption / decryption library is based on here My encryption key length is 2048 bits, but I see similar behavior with different key sizes. > I package my RSA encryption / decryption code into a jar file It is compiled on the server's machine through eclipse. > Programs that use encryption libraries on Android phones use the above libraries It is also built using eclipse. > The server program is built using NetBeans (because it's easier to do so)

Other issues

>Are there other free public key encryption algorithms / libraries available for Java? Do they work across platforms? What performance do they expect? Wait, I've studied it and haven't found much; Maybe I'm looking for the wrong keyword

Yo! I think so Thank you for your help in advance!

Solution

RSA encryption (or any encryption algorithm) should work regardless of the environment However, some systems may make different assumptions about the default fill and operation mode Ensure that when performing encryption and decryption, you can fully specify not only the algorithm, but also the operation mode (CBC, etc.) and padding If this doesn't work, I suggest you publish your code from the device and server so that we can check it more carefully

Edit to solve your problem, in Java, when you obtain a password from an encrypted package, you usually use the following code:

Cipher cipher;
cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");

The string provided to getInstance indicates that the runtime gets the password instance that will be populated using AES algorithm, password block link operation mode and pkcs5 There are some supported algorithms and filling I'll see more information about encryption in Java in this document from Oracle

More specifically, the string used to request a password is the format

<algorithm>/<mode of operation>/<padding>

To make matters worse, although Java provides many algorithms, operation modes and padding, not all algorithms can work together You will need to read the documentation to find the configuration string that works

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>