Type-safe Multiplatform cryptography library for Kotlin
CryptographyProvider.Default
.get(SHA512)
.hasher()
.hash("Kotlin is Awesome".encodeToByteArray())
Detailed documentation can be found on project website
cryptography-kotlin provides multiplatform API which consists of multiple components:
- Secure random with kotlin.Random like API which can be used independently of other modules
- common API to use different cryptography operations, like ciphers, digests, signatures, key derivation, Key agreement
- multiple algorithms definitions, like AES, RSA, ECDSA, ECDH, SHA, HMAC and PBKDF2
- multiple cryptography providers, like OpenSSL, WebCrypto, CryptoKit and JDK
The library doesn't implement any cryptography algorithm on its own, but wraps well-known future-proof solutions like OpenSSL 3.x, WebCrypto or JCA with type-safe multiplatform API providing uniform experience with aligned default behavior, and same expected results using identical parameters while allowing to use platform-specific capabilities. For supported algorithms, primitives and targets, please consult Providers documentation
Make sure that you use Kotlin 2.0.20+.
Using an earlier Kotlin version could still work, but not tested.
Additionally, it's possible to use BOM or Gradle version catalog to add dependencies easier.
The library is published to Maven Central, so make sure, that it’s added to repositories.
kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.whyoleg.cryptography:cryptography-core:0.4.0")
}
// or androidMain
jvmMain.dependencies {
implementation("dev.whyoleg.cryptography:cryptography-provider-jdk:0.4.0")
}
appleMain.dependencies {
implementation("dev.whyoleg.cryptography:cryptography-provider-apple:0.4.0")
// or openssl3 provider with better algorithms coverage and other native targets support
// implementation("dev.whyoleg.cryptography:cryptography-provider-openssl3-prebuilt:0.4.0")
}
wasmJsMain.dependencies {
implementation("dev.whyoleg.cryptography:cryptography-provider-webcrypto:0.4.0")
}
}
}
Snapshots of the development version are available in Sonatype's snapshot repository.
repositories {
maven("https://central.sonatype.com/repository/maven-snapshots/")
}
dependencies {
implementation("dev.whyoleg.cryptography:cryptography-core:0.5.0-SNAPSHOT")
}