-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample-aead.tcl
36 lines (33 loc) · 1.26 KB
/
example-aead.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package require tink
set keyset {{
"key": [{
"keyData": {
"keyMaterialType":
"SYMMETRIC",
"typeUrl":
"type.googleapis.com/google.crypto.tink.AesGcmKey",
"value":
"GiBWyUfGgYk3RTRhj/LIUzSudIWlyjCftCOypTr0jCNSLg=="
},
"keyId": 294406504,
"outputPrefixType": "TINK",
"status": "ENABLED"
}],
"primaryKeyId": 294406504
}}
set keyset_handle [::tink::register_keyset $keyset]
set plaintext "hello world"
set associated_data "some associated data"
set encrypted [::tink::aead::encrypt $keyset_handle $plaintext $associated_data]
set decrypted [::tink::aead::decrypt $keyset_handle $encrypted $associated_data]
#puts encrypted=[string range $encrypted 0 40]
puts decrypted=$decrypted
::tink::unregister_keyset $keyset_handle
set new_keyset [::tink::aead::create_keyset "AES256_GCM"]
puts new_keyset=$new_keyset
set new_keyset_handle [::tink::register_keyset $new_keyset]
set new_encrypted [::tink::aead::encrypt $new_keyset_handle $plaintext $associated_data]
set new_decrypted [::tink::aead::decrypt $new_keyset_handle $new_encrypted $associated_data]
#puts new_encrypted=[string range $new_encrypted 0 40]
puts new_decrypted=$new_decrypted
::tink::unregister_keyset $new_keyset_handle