Compare commits

..

2 Commits

Author SHA1 Message Date
1537dd1be3 replace IllegalArgumentException with require 2025-12-14 00:14:55 +01:00
8552d3dd2e update README 2025-12-13 21:13:17 +01:00
2 changed files with 21 additions and 18 deletions

View File

@@ -1,15 +1,18 @@
# Kotlin KDF
# kdf-kt
This library provides various [Key Derivation Function](https://en.wikipedia.org/wiki/Key_derivation_function)
implementations in Kotlin Multiplatform.
`kdf-kt` is a Kotlin Multiplatform library that provides common key derivation functions.
## Features
Supported functions:
- PBKDF2
* [PBKDF2](https://en.wikipedia.org/wiki/PBKDF2)
* Multiplatform support
* JVM
* JavaScript
* Native (Linux)
## Targets
| Target | Status |
|------------------|---------------|
| JVM | Supported |
| JavaScript | Supported |
| Native (Linux) | Supported |
| Native (Windows) | Not Supported |
## Installation
@@ -21,24 +24,24 @@ repositories {
}
dependencies {
implementation("com.infendro:kdf:1.0.3")
implementation("com.infendro:kdf:1.1.0")
}
```
## Usage
```kotlin
import com.infendro.hash.SHA256
import com.infendro.hash.`SHA-256`
import com.infendro.kdf.PBKDF2
fun main() {
// create a PBKDF2 instance using HMAC SHA256
val kdf = PBKDF2(SHA256)
// this example uses 32 bytes of length and 100_000 iterations
val kdf = PBKDF2(32, 100_000, `SHA-256`)
// securely hash value with some salt
// this example uses 100_000 iterations and 32 bytes of length
val value = "password".encodeToByteArray()
val salt = "...".encodeToByteArray()
val hash = kdf.hash(value, salt, 100_000, 32)
val value = "password".encodeToByteArray().asUByteArray()
val salt = "salt".encodeToByteArray().asUByteArray()
val hash = kdf.hash(value, salt)
}
```

View File

@@ -12,8 +12,8 @@ class PBKDF2(
function: HashFunction,
) : KDF {
init {
if (bytes < 1) throw IllegalArgumentException()
if (iterations < 1) throw IllegalArgumentException()
require(bytes > 0)
require(iterations > 0)
}
private val mac = HMAC(function)