Name Date Size #Lines LOC

..--

BUILD.bazelH A D25-Apr-20251.8 KiB7869

README.mdH A D25-Apr-20251.2 KiB4633

hybrid.pyH A D25-Apr-20252.9 KiB9356

hybrid_basic.pyH A D25-Apr-20253.8 KiB9848

hybrid_basic_test.pyH A D25-Apr-2025822 288

hybrid_test.shH A D25-Apr-20254.4 KiB15384

hybrid_test_private_keyset.jsonH A D25-Apr-2025332 21

hybrid_test_public_keyset.jsonH A D25-Apr-2025282 21

README.md

1# Python hybrid encryption example
2
3This example shows how to encrypt data with Tink using hybrid encryption.
4
5It demonstrates the basic steps of using Tink, namely loading key material,
6obtaining a primitive, and using the primitive to do crypto.
7
8The key material was generated with Tinkey:
9
10```shell
11$ tinkey create-keyset \
12    --key-template DHKEM_X25519_HKDF_SHA256_HKDF_SHA256_AES_256_GCM \
13    --out-format JSON --out hybrid_test_private_keyset.json
14
15$ tinkey create-public-keyset --in hybrid_test_private_keyset.json \
16    --in-format JSON --out-format JSON --out hybrid_test_public_keyset.json
17```
18
19## Build and Run
20
21### Bazel
22
23```shell
24$ git clone https://github.com/google/tink
25$ cd tink/python/examples
26$ bazel build ...
27```
28
29You can then encrypt a file:
30
31```shell
32$ echo "some data" > testdata.txt
33$ ./bazel-bin/hybrid/hybrid --mode encrypt \
34    --keyset_path ./hybrid/hybrid_test_public_keyset.json \
35    --input_path testdata.txt --output_path testdata.txt.encrypted
36```
37
38Or decrypt the file with:
39
40```shell
41$ ./bazel-bin/hybrid/hybrid --mode decrypt \
42    --keyset_path ./hybrid/hybrid_test_private_keyset.json \
43    --input_path testdata.txt.encrypted --output_path testdata.txt.decrypted
44$ diff testdata.txt testdata.txt.decrypted
45```
46