/ecdsa-kotlin

A simple, lightweight, fast elliptical curve cryptography library in kotlin.

Primary LanguageKotlinMIT LicenseMIT

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

ecdsa-kotlin

CircleCI

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

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

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

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(...)
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)