Different RSA public key created on Android

I managed to create a public key in my Java desktop environment and I got something like this

Sun RSA public key, 1024 bits modulus: 101700973019391285593457598101942678753508114287289699162184623605939671495532511783006850112834969917970271633181351680298749946797462542179729127916916336425952724141383800466274935950042225686754068132826643586090512962724382324158485291344703936377718522573879330753020035687831145457530843148690890911921 public exponent: 65537

But on an Android device, when I get the key as a string and use KeyFactory to generate the public key, I get the following:

OpenSSLRSAPublicKey{modulus=90d3b5cefc50dc42828cee8d718876f7573b4c9287dddf808e73cb66266c2004165217f86d0f0192de0bb88b3aac2002303ee8b1c926e9bc54189a5ec5a12bb293df0b3c6ff2458a63098f712f0b72218ce301c38de3971ae8c6c646160a5e2e24dc07679e5a82ada1233ecf5eca3d0d1f483d1c9f059 a23deed537c670b70b1,publicExponent=10001}

There is a mismatch in the keys. I tried SpongyCastle. I am still getting OpenSSL result on Android.

What am I missing?

+6
source share
1 answer

There are no discrepancies between the keys. One is printed in base 16 (hexadecimal), while the other is printed in decimal. Just try the following code to confirm:

 BigInteger bi = new BigInteger( "90d3b5cefc50dc42828cee8d718876f7573b4c9287dddf808e73cb66266c2004165217f86d0f0192de0bb88b3aac2002303ee8b1c926e9bc54189a5ec5a12bb293df0b3c6ff2458a63098f712f0b72218ce301c38de3971ae8c6c646160a5e2e24dc07679e5a82ada1233ecf5eca3d0d1f483d1c9f059a23deed537c670b70b1", 16); System.out.println(bi.toString(10)); 

The result will be the same as your key without OpenSSL.

What is happening here is that on different platforms there are different cryptographic providers that perform cryptographic operations. The results will be the same, but there will be slight differences that will be noticed, for example, when calling toString() .

+4
source

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


All Articles