Overview¶
CryptographyProvider.Default
.get(SHA512)
.hasher()
.hash("Kotlin is Awesome".encodeToByteArray())
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, CryptoKit, 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
Core primitives are:
- CryptographyProvider provides a way to get specific CryptographyAlgorithm by its id
- CryptographyProvider.Default is the default provider. After adding a dependency to a provider (like openssl3), it will be automatically registered and available via the default provider
- inheritors of CryptographyAlgorithm (like f.e. AES) provide access to operations (like f.e. ciphers)
Using in your projects¶
Make sure that you use Kotlin 2.2.0+. Using an earlier Kotlin version could still work, but not tested. 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.5.0")
implementation("dev.whyoleg.cryptography:cryptography-provider-optimal:0.5.0")
}
}
}
Additionally, it’s possible to use BOM or Gradle version catalog to add dependencies easier.