Cryptographic interoperability between Android and iOS.
Cryptographic interoperability between Android and iOS.
This project’s goal is to provide Android equivalents of the cryptographic functions inside Apple’s Security framework for the purpose of easy cryptographic interoperability.
let plaintext: NSData = ...
let privateKey: SecKey = ...
let publicKey: SecKey = ...
let signature = SecKeyCreateSignature(privateKey, .ecdsaSignatureDigestX962SHA256, plaintext.sha256Digest() as CFData, nil)
let valid = SecKeyVerifySignature(publicKey, .ecdsaSignatureDigestX962SHA256, plaintext.sha256Digest() as CFData, signature as CFData, nil)
XCTAssertTrue(valid)
val plaintext: ByteArray = ...
val privateKey: ECPrivateKey = ...
val publicKey: ECPublicKey = ...
val signature = SecKeyCreateSignature(privateKey, SecKeyAlgorithm.ECDSA_SIGNATURE_DIGEST_X962_SHA256, plaintext)
val valid = SecKeyVerifySignature(publicKey, SecKeyAlgorithm.ECDSA_SIGNATURE_DIGEST_X962_SHA256, plaintext, signature)
Assert.assertTrue(valid)
let plaintext: NSData = ...
let privateKey: SecKey = ...
let publicKey: SecKey = ...
let encryptedData = SecKeyCreateEncryptedData(publicKey, .eciesEncryptionStandardVariableIVX963SHA256AESGCM, plaintext as CFData, nil)
let decryptedData = SecKeyCreateDecryptedData(privateKey, .eciesEncryptionStandardVariableIVX963SHA256AESGCM, encryptedData as CFData, nil)
XCTAssertTrue(plaintext == decryptedData)
val plaintext: ByteArray = ...
val privateKey: ECPrivateKey = ...
val publicKey: ECPublicKey = ...
val encryptedData = SecKeyCreateEncryptedData(publicKey, SecKeyAlgorithm.ECIES_ENCRYPTION_STANDARD_VARIABLE_IV_X963_SHA256_AES_GCM, plaintext)
val decryptedData = SecKeyCreateDecryptedData(privateKey, SecKeyAlgorithm.ECIES_ENCRYPTION_STANDARD_VARIABLE_IV_X963_SHA256_AES_GCM, encryptedData)
Assert.assertTrue(Arrays.equals(plaintext, decryptedData))
This software was built using Android Studio 3.3.2 on macOS 10.14.3 with the Android 28 SDK. You should be able to open the project and run the tests. Note: before running the local unit tests, run the instrumented tests first.
Minimum Android 26 SDK
Contributions are welcome!
This project was inspired by BlueECC.
This software is distributed under the terms and conditions of the Apache License 2.0.