Skip to content

dshatz/ecdsa-kotlin-mpp

Repository files navigation

               _           
              | |          
   ___  ___ __| |___  __ _ 
  / _ \/ __/ _` / __|/ _` |
 |  __/ (_| (_| \__ \ (_| |
  \___|\___\__,_|___/\__,_|              
                           

ecdsa-kotlin

A simple, yet lightweight, fast elliptical curve cryptography library in kotlin. Please note that this library must undergo further testing before using in production.

implementation("com.dshatz.kmp:ecdsa:1.0.1")

Supported Curves

This library comes with a plethora of curves, but do not worry! You can create your own curve to fit your cryptographic needs. Below are listed the curves that come out of the box.

  • Secp256k1
  • Secp256r1

Hashing

This library comes with some hashing algorithms to create signatures, you can implement your own if your favorite hashing algorithm is not included. Below are listed the hashing algorithms that come out of the box.

  • SHA256
  • SHA512

Supported Kotlin targets

  • JVM
  • Android
  • Native (Linux ARM, Linux X64, OSX X64, OSX Arm, Windows)

Creating a Key Pair

Creating a key pair is very simple, you may generate a random key pair, or generate one from a private key. The private key is simply a very large number.

// generates a random key pair on the secp256k1 curve
val randomKeys = EcKeyGenerator.newInstance(Secp256k1) 

// generates a random key pair on the secp256k1 curve with a private key
val privateKey = BigInteger.fromByteArray(...)
val fromPrivateKey = EcKeyGenerator.newInstance(privateKey, Secp256k1) 

Signing

Signing is just as easy as creating a key pair. You may sign whatever data you please.

// signs data [0x13, 0x37]
val data = byteArrayOf(0x13, 0x37)
val keyPair = EcKeyGenerator.newInstance(Secp256k1) 
val signature = EcSign.signData(keyPair, data, EcSha256)

Verifying

After creating a signature, you can verify that the public key signed the data.

// verifies that the public key signed the data
val publicKey = EcPoint(...)
val signature = EcSignature(...)
val data = byteArrayOf(0x13, 0x37)
val isValid = EcSign.verifySignature(publicKey, data, EcSha256, signature)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published