Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andreypfau/curve25519-kotlin
A pure Kotlin/Multiplatform implementation of group operations on Curve25519.
https://github.com/andreypfau/curve25519-kotlin
cryptography curve25519 ed25519 edwards-curve kotlin kotlin-js kotlin-jvm kotlin-multiplatform kotlin-native montgomery-curve x25519
Last synced: 2 months ago
JSON representation
A pure Kotlin/Multiplatform implementation of group operations on Curve25519.
- Host: GitHub
- URL: https://github.com/andreypfau/curve25519-kotlin
- Owner: andreypfau
- License: mit
- Created: 2022-10-22T01:22:32.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-03T20:44:54.000Z (8 months ago)
- Last Synced: 2024-05-04T02:48:59.163Z (8 months ago)
- Topics: cryptography, curve25519, ed25519, edwards-curve, kotlin, kotlin-js, kotlin-jvm, kotlin-multiplatform, kotlin-native, montgomery-curve, x25519
- Language: Kotlin
- Homepage:
- Size: 1.06 MB
- Stars: 13
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# curve25519-kotlin
[![Maven Central](https://img.shields.io/maven-central/v/io.github.andreypfau/curve25519-kotlin.svg)](https://search.maven.org/artifact/io.github.andreypfau/curve25519-kotlin/0.0.6/pom)
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![Kotlin](https://img.shields.io/badge/kotlin-1.7.20-blue.svg?logo=kotlin)](http://kotlinlang.org)**A pure Kotlin/Multiplatform implementation of group operations on Curve25519.**
### Gradle Kotlin DSL:
```kotlin
dependencies {
implementation("io.github.andreypfau:curve25519-kotlin:0.0.7")
}
```### Apache Maven:
```xml
io.github.andreypfau
curve25519-kotlin-jvm
0.0.7```
## Examples:
### Generate key-pair from random
```kotlin
val privateKey: Ed25519PrivateKey = Ed25519.generateKey(Random)
val publicKey: Ed25519PublicKey = privateKey.publicKey()
```### Generate key-pair from seed bytes
```kotlin
val seedBytes: ByteArray = ByteArray(32)
val privateKey: Ed25519PrivateKey = Ed25519.keyFromSeed(seedBytes)
val publicKey: Ed25519PublicKey = privateKey.publicKey()
```### Signing messages & verify signatures
```kotlin
val message: ByteArray = "test message".encodeToByteArray()
val signature: ByteArray = privateKey.sign(message)check(publicKey.verify(message, signature)) // Valid message returns true
val invalidMessage = "invalid message".encodeToByteArray()
check(!publicKey.verify(invalidMessage, signature)) // Invalid message returns false
```### Shared key calculation
```kotlin
val alicePrivate = Ed25519.generateKey(Random)
val alicePublic = alicePrivate.publicKey()val bobPrivate = Ed25519.generateKey(Random)
val bobPublic = bobPrivate.publicKey()val aliceShared = alicePrivate.sharedKey(bobPublic)
val bobShared = bobPrivate.sharedKey(alicePublic)check(aliceShared.contentEquals(bobShared))
```