简体   繁体   中英

How can I generate a RSA Public key in Java that can be used on Android and on iOS?

I have a webservice in java using Spring that needs to generate a RSA Key Pair and send the PUBLIC KEY via this WS, so that a ANDROID and a iOS app can read and encrypt a STRING using this public key.

On every WS request, it must to generate a new Key Pair.

I've try to use the KeyPair class in Java an only the ANDROID app has recognized the public key.

How can I do that? Can someone help me with this?

Upon further study, I found that iOS's secKeyWrapper can only accept key's data in ASN.1 DER format. Any attempts to pass data in any other format would definitely fail on iOS.

Solved the problem by dumping the RSA keys in PEM format and used the approach from following link to read PEM and convert to ASN.1 DER format and passed the same to SecKeyWrapper!

Alternate approach: Problem could have also be solved by using OpenSSL libraries for iOS (refer Generate Public Key From Modulus & Exponent on iOS using OpenSSL ) and create RSA objects with input modulus & exponent (base64encoded) data for the public key shared from any other platform.

首选项-> SSH2->密钥管理->选择RSA->在库空间上移动鼠标直到生成公钥->单击保存私钥(公钥和私钥都将保存在C:// Users / User中名称/.ssh/id_rsa.pub密钥),仅此而已...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM