Sharing and saving RSA is a public key on a java server and vice versa

My requirements:

Requirement 1: Share the Java server.

Steps:

  • Creating public keys in an iOS application.
  • Store the generated keys in the keychain.
  • Send the generated public key to the java server.
  • The Java server must be able to store the shared public key in the database.

Requirement 2: Keep public key sent using java server.

Steps:

  • The Java server sends the public key of another user.
  • Process data sent by the java server and generating a public key from it.
  • Store the generated key in the key chain, which can subsequently be obtained to encrypt the transmitted message.

1-2 1, , SecKeyWrapper ( CommonCrypto):

- (void)generateKeyPair:(NSUInteger)keySize

1: , java-?

getPublicKeyBits , NSData, - googling , DER.

2: NSData , , , ByteBuffer, , android, ?

3: ?

, :

№1:

Android End

  • Android ( openssl wrapper)

iOS End

  • ios, , : qaru.site/questions/431052/...
  • NSData, NSUTF8StringEncoding
  • - wrapSymmetricKey: keyRef: , SecKeyWrapper ( CryptoExercise) 1 , 2 .
  • NSData ( ), base64encoded string, Android.

Android End

  1. base64encoded,

:

- RSA

№ 2: ( , - https://github.com/superwills/iOSRSAPublicKeyEncryption, iOS , , )

iOS End

  1. , URL
  2. :

    SecKeyWrapper * secKeyWrapper = [SecKeyWrapper sharedWrapper]; SecKeyRef PublicKey = [secKeyWrapper getPublicKeyRefFromDerCertificate: kCertificatePath]; NSData * dataToBeEncrypted = [kStringToBeEncrypted dataUsingEncoding: NSUTF8StringEncoding]; NSData * encryptedText = [secKeyWrapper wrapSymmetricKey: dataToBeEncrypted keyRef: receivedPublicKey];

  3. NSData base64encoded string

  1. , :

    | openssl rsautl -decrypt -inkey rsaPrivate.pem

:

- rsa: RSA_EAY_PRIVATE_DECRYPT: , Len:/SourceCache/OpenSSL098/OpenSSL098-47.1/src/crypto/rsa/rsa_eay.c

?

+4
1

, . , , , 64 ( ----- BEGIN/END PUBLIC KEY ----- header/footer), , . , , Base64, . , ( , base64, Android, iOS , - ). , (getting error - too much data for RSA block), , , , . RSA , , , , . , , - , / , , , RSA. RSA.

, , , , , , ( , , , , - ).

0

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


All Articles