Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | - | - | ||||
BUILD.bazel | H A D | 25-Apr-2025 | 1.8 KiB | 78 | 69 | |
README.md | H A D | 25-Apr-2025 | 1.2 KiB | 46 | 33 | |
hybrid.py | H A D | 25-Apr-2025 | 2.9 KiB | 93 | 56 | |
hybrid_basic.py | H A D | 25-Apr-2025 | 3.8 KiB | 98 | 48 | |
hybrid_basic_test.py | H A D | 25-Apr-2025 | 822 | 28 | 8 | |
hybrid_test.sh | H A D | 25-Apr-2025 | 4.4 KiB | 153 | 84 | |
hybrid_test_private_keyset.json | H A D | 25-Apr-2025 | 332 | 2 | 1 | |
hybrid_test_public_keyset.json | H A D | 25-Apr-2025 | 282 | 2 | 1 |
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