tree: 842e172dff5e5cb94db6e9bff92252f56cf9c38b [path history] [tgz]
  1. BUILD.bazel
  2. hybrid_example_test.sh
  3. hybrid_test_private_keyset.json
  4. hybrid_test_public_keyset.json
  5. HybridExample.java
  6. README.md
java_src/examples/hybrid/README.md

Java hybrid encryption example

This example shows how to encrypt data with Tink using hybrid encryption.

It demonstrates the basic steps of using Tink, namely loading key material, obtaining a primitive, and using the primitive to do crypto.

The key material was generated with Tinkey:

tinkey create-keyset \
    --key-template DHKEM_X25519_HKDF_SHA256_HKDF_SHA256_AES_256_GCM \
    --out-format JSON --out hybrid_test_private_keyset.json

tinkey create-public-keyset --in hybrid_test_private_keyset.json \
    --in-format JSON --out-format JSON --out hybrid_test_public_keyset.json

Build and run

Bazel

git clone https://github.com/google/tink
cd tink/java_src/examples
bazel build hybrid_example

Encrypt a file:

echo "some data" > testdata.txt
../bazel-bin/hybrid/hybrid_example encrypt \
    ../hybrid/hybrid_test_public_keyset.json \
    testdata.txt testdata.txt.encrypted

Decrypt a file:

../bazel-bin/hybrid/hybrid_example decrypt \
    ../hybrid/hybrid_test_private_keyset.json \
    testdata.txt.encrypted testdata.txt.decrypted

diff testdata.txt testdata.txt.decrypted