1

Is there any encryption algorithm that is generic across all platforms? Is RSA generic across SUN/IBM JRE?

Another question: will base64Encoder / base64Decoder sun.misc.BASE64Decode / sun.misc.BASE64Encoder behave the same way in IBM JRE?

Also are there differences in using this algorithms in the 32bit / 64bit JREs? If yes, then how to tackle them?

2
  • 1
    They should be implementing the same algorithm. Have you encountered a specific problem, encrypting with one JRE and decrypting with another? May 28, 2015 at 8:39
  • As long as the algorithm is the same on the bitwise level regarding the ciphertext output, then it will be compatible across platforms. How those bits are computed might differ, but that doesn't affect the result.
    – Natanael
    May 28, 2015 at 11:02

2 Answers 2

6

The standard name documentation of the Java Cryptography Architecture (JCE) contains a section about implementation requirements. For both Java 7 and Java 8 it contains the following entries for Cipher with regards to RSA:

RSA/ECB/PKCS1Padding (1024, 2048)
RSA/ECB/OAEPWithSHA-1AndMGF1Padding (1024, 2048)
RSA/ECB/OAEPWithSHA-256AndMGF1Padding (1024, 2048)

to make sure you got the right one, specify the complete string (excluding the key sizes within the parenttheses of course). So that would be "RSA/ECB/OAEPWithSHA-1AndMGF1Padding" for OAEP padding.

RSA is a set of internationally standardized algorithms (defined in the PKCS#1 standards and the RFC's derived from those standards). The implementations should confirm to the test vectors for any platform. RSA for instance uses big endian encoding, even on little endian platforms.


The Base64Encoder is a Sun internal class. It may even be inconsistent across implementations and it may disappear without warning. It is used a lot unfortunately so Oracle and others may decide to leave it in place, just in case. You should never ever use Sun internal classes. Many static code validators and even IDE's will flag this as an error.

For Java 8 compatible runtimes you should use the Base64 class. For earlier versions you should go with a library. The Apache Commons Codec is often used. Google Guava is used a lot as well and has a set of codecs too.

Base 64 has been around for a long time. It should not run any differently on 32 bit or 64 bit on any platform, as long as you are sure you use the same character encoding. UTF-8 encoding - compatible with US ASCII for base 64 - should be preferred.


Finally there are the Java Bouncy Castle libraries and provider. The Bouncy Castle libraries contain an ever growing amount of cryptographic functionality that can be used on any Java runtime. The provider is used to allow much of this functionality to be used through the Java JCA/JCE. And it of course also contains a Base64 class in the "lightweight" API.


As long as you use the API correctly Java is fully compatible on 32 and 64 bit, big endian or little endian processors. It should not even matter if you use Linux, Windows, MacOS. Android should be compatible as well, although it is not an official Java distribution.

9
  • Thanks for detailed explanation.I need to used encryption / decryption algorithm which is generic across all JREs / all platforms [ 32bit / 64bit].RSA is a generic algorithm which will behave same way in across all platforms right? May 28, 2015 at 9:24
  • publicKey - public key as a string base64encoded // get an RSA cipher object and print the provider Cipher cipher = Cipher.getInstance(ENC_DEC_ALGORITHM); PublicKey key = loadPublicKey(publicKey); // encrypt the plain text using the public key cipher.init(Cipher.ENCRYPT_MODE, key); cipherText = cipher.doFinal(text.getBytes()); May 28, 2015 at 9:41
  • how cipher.getInstance() will behave in IBM jre ? May 28, 2015 at 9:43
  • It returns a Cipher instance backed by a CipherSpi instance from the highest prio provider that contains the algorithm string. Or it thrown an exception if it cannot find the algorithm of course. Read the documentation. May 28, 2015 at 9:56
  • what if I generate the key with RSA algorithm in SUN JRE - 1.7 64 bit system and ask the IBM SDK [ with 32 bit / 64 bit ] to encrypt with given public key and try to decrypt it with again in SUN JRE using private key . how it wll behave usually ? any well known issues which might come up ? May 28, 2015 at 11:27
0

About the base64 encoder: You should not use sun.misc packages they are not part of the official API, so it could be possible that these classes are not available in other VMs.

Use the org.apache Base64 decoder.

RSA is an encryption standard/algorithm so with the rights keys you should encrypt/decrypt accross VMs.

2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .