amitaymolko / react-native-rsa-native

A native implementation of RSA key generation and encryption/decryption.
MIT License
232 stars 112 forks source link

Differently formatted keys on android and iOS #157

Open aleksa-milojkovic-accordia opened 11 months ago

aleksa-milojkovic-accordia commented 11 months ago

While using the RSA.generateKeys() method I've noticed that it generates differently formatted keys depending on the OS. I've noticed that the Android one is very differently generated than the iOS one since the headers are different and on android you have a lot more new lines.

Here is the example code And here are the the generated keys for Android and iOS Android.txt iOS.txt

it's causing us problems because our backend needs to verify the JWT that's signed by the device's private key, but when our backend gets the public key from the Android device it says its not in SPKI. The backend uses Jose to verify the SPKI public key.

Jose.txt - this is the output we get from JOSE

I've looked at the native modules for it and noticed there are differences between the java and swift code. Is it maybe a problem with the native modules how they generate the keys on Android or with Jose?

Thank you in advance.

vinithreddy3 commented 10 months ago

@aleksa-milojkovic-accordia Seems there is a fn -> RSAKeychain.getPublicKeyRSA for iOS only to get public key in pksc1 format similar to android. I used this function on iOS & the response is now formatted similar to android.

You can give a try with RSAKeychain instead of RSA. Check this older thread as well https://github.com/amitaymolko/react-native-rsa-native/issues/110