tree: 1bc00f9f4a5bbf1321817e05ece019c4e6adb558 [path history] [tgz]
  1. BUILD.bazel
  2. cleartext_keyset_example_test.sh
  3. CleartextKeysetExample.java
  4. README.md
java_src/examples/cleartextkeyset/README.md

Java cleartext keysets example

This example shows how to generate or load a cleartext keyset, obtain a primitive, and use the primitive to do crypto.

WARNING: This is not recommended, consider protecting your keysets with a key management system.

Build and run

Bazel

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

Generate a cleartext keyset:

./bazel-bin/cleartextkeyset/cleartext_keyset_example generate aes128_gcm_test_keyset.json

Encrypt a file with the resulting keyset:

echo "some data" > testdata.txt
./bazel-bin/cleartextkeyset/cleartext_keyset_example encrypt \
    aes128_gcm_test_keyset.json \
    testdata.txt testdata.txt.encrypted

Decrypt the file with the resulting keyset:

./bazel-bin/cleartextkeyset/cleartext_keyset_example decrypt \
    aes128_gcm_test_keyset.json \
    testdata.txt.encrypted testdata.txt.decrypted

diff testdata.txt testdata.txt.decrypted