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

View File

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