Kotlin HPKE library and samples.
- Build and run tests in Docker (recommended):
docker compose -f docker/compose.dev.yaml run --rm dev ./gradlew --no-daemon test- Run the sample module locally with Gradle 9.5.1 on JDK 17+:
./gradlew :hpke-sample:run- Kotlin sample (from project root):
./gradlew :hpke-sample:run --args='kotlin'- Java sample (compile & run via Gradle):
./gradlew :hpke-sample:compileJava :hpke-sample:run --args='java'Kotlin example (create an Hpke instance and seal/open):
val config = HpkeConfig(kem = KemType.DHKEM_P256_HKDF_SHA256,
kdf = KdfType.HKDF_SHA256,
aead = AeadType.AES_GCM_256)
val hpke = HpkeFactory.create(config, HpkeMode.Base)
val (enc, ct) = HpkeOps.seal(hpke, plaintext = "hello".toByteArray())
val pt = HpkeOps.open(hpke, enc, ct)Java example (call Kotlin HpkeFactory from Java):
HpkeConfig config = new HpkeConfig(KemType.DHKEM_P256_HKDF_SHA256,
KdfType.HKDF_SHA256,
AeadType.AES_GCM_256);
Hpke hpke = HpkeFactory.INSTANCE.create(config, HpkeMode.Base, CryptoProvider.BouncyCastle);
Encapsulated enc = HpkeOpsKt.seal(hpke, "hello".getBytes());
byte[] pt = HpkeOpsKt.open(hpke, enc.getEnc(), enc.getCiphertext());The library bundles implementations for:
- KEMs:
DHKEM_P256_HKDF_SHA256,DHKEM_X25519_HKDF_SHA256 - KDFs:
HKDF_SHA256,HKDF_SHA384,HKDF_SHA512 - AEADs:
AES_GCM_256,AES_GCM_128,CHACHA20_POLY1305
For X25519 and ChaCha20-Poly1305 ensure your JDK supports these algorithms or use the BouncyCastle provider. To force BouncyCastle from Java, pass CryptoProvider.BouncyCastle to HpkeFactory.create (Kotlin default is already BouncyCastle).
- Development remains Docker-first. Build and test locally with Docker Compose:
docker compose -f docker/compose.dev.yaml run --rm dev ./gradlew --no-daemon test- Build locally with Gradle when you want to use your host JDK 17+:
./gradlew clean build- For JitPack distribution, the repo includes
jitpack.ymland publishes thehpke-coremodule withpublishToMavenLocalon JDK 17 into$HOME/.m2/repository, creating the directory first so JitPack can detect the artifact. - The published Maven coordinates for the core library are
com.github.kenjiohtsuka:khpke:0.0.4-style snapshots from tags, with thehpke-coreartifact id. - If you change the public API or modules, make sure tags are created from a passing build before publishing.
- Build toolchain: Gradle 9.5.1
- Minimum bytecode target: Java 11
- Development/runtime JDK: 17+
- Core crypto provider: BouncyCastle 1.70
- Modules:
hpke-core,hpke-test,hpke-sample - Docker dev flow:
docker/compose.dev.yaml - CI compose flow:
docker/compose.yaml
- The sample module demonstrates all four HPKE modes (Base, PSK, Auth, AuthPSK). See the
hpke-samplepackage for runnable examples in Kotlin and Java. - If you encounter algorithm support errors, install BouncyCastle provider and/or run inside Docker (images used in CI include the provider).
See hpke-core for lower-level API docs and hpke-sample for ready-to-run examples.