Skip to content

JDK

Provides implementation of CryptographyProvider via JDK built-in JCA

For supported targets and algorithms, please consult Supported primitives section

Limitations

  • KeyFormat: doesn’t support JWK key format yet

Example

val provider = CryptographyProvider.JDK // or CryptographyProvider.Default

// get some algorithm
provider.get(SHA512)

Using in your projects

dependencies {
    implementation("dev.whyoleg.cryptography:cryptography-provider-jdk:0.5.0")
}

Custom Java providers

Some specific algorithms (SHA3 family of digests on JDK 8) or parameters (secp256k1 curve for ECDSA) could be not supported by default JDK provider, but it doesn’t mean, that you cannot use them with cryptography-kotlin. There is a possibility to create CryptographyProvider from java.util.Provider, f.e. using BouncyCastle:

val provider = CryptographyProvider.JDK(BouncyCastleProvider())

// get some algorithm which not supported on a JDK version or platform (in case of Android)
provider.get(SHA512)

The library provides an ability to configure the default security provider used by JDK provider via DefaultJdkSecurityProvider. In addition to that, it’s possible to use BouncyCastle as the default provider via an additional dependency:

dependencies {
    implementation("dev.whyoleg.cryptography:cryptography-provider-jdk-bc:0.5.0")
}

Android support

JDK provider is also tested via Android emulator on API level 21, 27 and 33. Supported algorithms on Android highly depend on Android API level and used provider. Some limitations are:

  • default provider doesn’t support RSA-SSA-PSS or SHA3 algorithms

For better compatibility, you can use BouncyCastle provider as shown in Custom Java providers.