Home > front end >  Is there a way to use Curve25519 Elliptic Curve encryption method on Android?
Is there a way to use Curve25519 Elliptic Curve encryption method on Android?

Time:12-02

I want to create a public and private key using curve25519 to encrypt some data in a file. It looks like iOS has something in the CryptoKit to allow clients to build something like this below. How can I use Curve25519 encryption in an Android project? I could not find any android-specific libraries that come with it. Any suggestion on how I can do this would be greatly appreciated.

let albusPrivateKey = Curve25519.KeyAgreement.PrivateKey()
let albusPublicKeyData = albusPrivateKey.publicKey.rawRepresentation
let harryPrivateKey = Curve25519.KeyAgreement.PrivateKey()
let harryPublicKeyData = harryPrivateKey.publicKey.rawRepresentation

CodePudding user response:

Android has the androidx.security.crypto packages built on Google Tink.

You'll probably have to access Google Tink directly as Curve25519 has an Alpha annotation signifying:

Signifies that a public API (public class, method or field) is subject to incompatible changes, or even removal, in a future release. An API bearing this annotation is exempt from any compatibility guarantees made by Tink.

The presence of this annotation might also indicate that the quality or performance of the API in question not ready for production.

It is unsafe to depend on alpha APIs.

CodePudding user response:

  val keyPairGenerator = KeyPairGenerator.getInstance("x25519")
  val keyPair = keyPairGenerator.generateKeyPair()

I was able to just do this and this worked for me. This is from the Java security package.

  • Related