项目作者: zssz

项目描述 :
Cryptographic interoperability between Android and iOS.
高级语言: Kotlin
项目地址: git://github.com/zssz/AppleCryptoInteroperability.git
创建时间: 2019-03-18T07:36:02Z
项目社区:https://github.com/zssz/AppleCryptoInteroperability

开源协议:Other

下载


AppleCryptoInteroperability

Build Status Platform Language Documented GitHub license

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.

Examples

Signature / Verification

iOS

  1. let plaintext: NSData = ...
  2. let privateKey: SecKey = ...
  3. let publicKey: SecKey = ...
  4. let signature = SecKeyCreateSignature(privateKey, .ecdsaSignatureDigestX962SHA256, plaintext.sha256Digest() as CFData, nil)
  5. let valid = SecKeyVerifySignature(publicKey, .ecdsaSignatureDigestX962SHA256, plaintext.sha256Digest() as CFData, signature as CFData, nil)
  6. XCTAssertTrue(valid)

Android Equivalent

  1. val plaintext: ByteArray = ...
  2. val privateKey: ECPrivateKey = ...
  3. val publicKey: ECPublicKey = ...
  4. val signature = SecKeyCreateSignature(privateKey, SecKeyAlgorithm.ECDSA_SIGNATURE_DIGEST_X962_SHA256, plaintext)
  5. val valid = SecKeyVerifySignature(publicKey, SecKeyAlgorithm.ECDSA_SIGNATURE_DIGEST_X962_SHA256, plaintext, signature)
  6. Assert.assertTrue(valid)

Encryption / Decryption

iOS

  1. let plaintext: NSData = ...
  2. let privateKey: SecKey = ...
  3. let publicKey: SecKey = ...
  4. let encryptedData = SecKeyCreateEncryptedData(publicKey, .eciesEncryptionStandardVariableIVX963SHA256AESGCM, plaintext as CFData, nil)
  5. let decryptedData = SecKeyCreateDecryptedData(privateKey, .eciesEncryptionStandardVariableIVX963SHA256AESGCM, encryptedData as CFData, nil)
  6. XCTAssertTrue(plaintext == decryptedData)

Android

  1. val plaintext: ByteArray = ...
  2. val privateKey: ECPrivateKey = ...
  3. val publicKey: ECPublicKey = ...
  4. val encryptedData = SecKeyCreateEncryptedData(publicKey, SecKeyAlgorithm.ECIES_ENCRYPTION_STANDARD_VARIABLE_IV_X963_SHA256_AES_GCM, plaintext)
  5. val decryptedData = SecKeyCreateDecryptedData(privateKey, SecKeyAlgorithm.ECIES_ENCRYPTION_STANDARD_VARIABLE_IV_X963_SHA256_AES_GCM, encryptedData)
  6. Assert.assertTrue(Arrays.equals(plaintext, decryptedData))

Supported SecKey Algorithms

Signature / Verification

Encryption / Decryption

Requirements

Build

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.

Runtime

Minimum Android 26 SDK

Contributing

Contributions are welcome!

Acknowledgement

This project was inspired by BlueECC.

License

This software is distributed under the terms and conditions of the Apache License 2.0.