-
Notifications
You must be signed in to change notification settings - Fork 0
/
example-hybrid.tcl
80 lines (68 loc) · 3.15 KB
/
example-hybrid.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package require tink
set hybrid_test_private_keyset {{
"primaryKeyId": 548859458,
"key": [
{
"keyData": {
"typeUrl": "type.googleapis.com/google.crypto.tink.EciesAeadHkdfPrivateKey",
"value": "EowBEkQKBAgCEAMSOhI4CjB0eXBlLmdvb2dsZWFwaXMuY29tL2dvb2dsZS5jcnlwdG8udGluay5BZXNHY21LZXkSAhAQGAEYARohAKjjAxgGmD9j90UyzNunoC04kWqaWiXGFRhOYfLS7Z2tIiEAhqqb+D0Din92zHwGQefzui0hma5khIZQCWyWHHVgNpsaIBQrEEuEn3hClVKM+4bsvmaUOqFYMbl7E6lNFJzbr+lp",
"keyMaterialType": "ASYMMETRIC_PRIVATE"
},
"status": "ENABLED",
"keyId": 548859458,
"outputPrefixType": "TINK"
}
]
}}
set hybrid_test_public_keyset {{
"primaryKeyId": 548859458,
"key": [
{
"keyData": {
"typeUrl": "type.googleapis.com/google.crypto.tink.EciesAeadHkdfPublicKey",
"value": "EkQKBAgCEAMSOhI4CjB0eXBlLmdvb2dsZWFwaXMuY29tL2dvb2dsZS5jcnlwdG8udGluay5BZXNHY21LZXkSAhAQGAEYARohAKjjAxgGmD9j90UyzNunoC04kWqaWiXGFRhOYfLS7Z2tIiEAhqqb+D0Din92zHwGQefzui0hma5khIZQCWyWHHVgNps=",
"keyMaterialType": "ASYMMETRIC_PUBLIC"
},
"status": "ENABLED",
"keyId": 548859458,
"outputPrefixType": "TINK"
}
]
}}
set hybrid_test_private_keyset_handle [::tink::register_keyset $hybrid_test_private_keyset]
set hybrid_test_public_keyset_handle [::tink::register_keyset $hybrid_test_public_keyset]
set plaintext "hello world"
set context_info "some context info"
set encrypted [::tink::hybrid::encrypt $hybrid_test_public_keyset_handle $plaintext $context_info]
set decrypted [::tink::hybrid::decrypt $hybrid_test_private_keyset_handle $encrypted $context_info]
puts decrypted=$decrypted
::tink::unregister_keyset $hybrid_test_private_keyset_handle
::tink::unregister_keyset $hybrid_test_public_keyset_handle
set hpke_test_private_keyset {{
"primaryKeyId": 958452012,
"key": [
{
"keyData": {
"typeUrl": "type.googleapis.com/google.crypto.tink.HpkePrivateKey",
"value": "EioSBggBEAEYAhogVWQpmQoz74jcAp5WOD36KiBQ71MVCpn2iWfOzWLtKV4aINfn8qlMbyijNJcCzrafjsgJ493ZZGN256KTfKw0WN+p",
"keyMaterialType": "ASYMMETRIC_PRIVATE"
},
"status": "ENABLED",
"keyId": 958452012,
"outputPrefixType": "TINK"
}
]
}}
set new_hybrid_test_private_keyset [::tink::hybrid::create_private_keyset "ECIES_X25519_HKDF_HMAC_SHA256_AES256_GCM"]
puts new_hybrid_test_private_keyset=$new_hybrid_test_private_keyset
set new_hybrid_test_public_keyset [::tink::create_public_keyset $new_hybrid_test_private_keyset]
puts new_hybrid_test_public_keyset=$new_hybrid_test_public_keyset
set new_hybrid_test_private_keyset_handle [::tink::register_keyset $new_hybrid_test_private_keyset]
set new_hybrid_test_public_keyset_handle [::tink::register_keyset $new_hybrid_test_public_keyset]
set plaintext "hello world"
set context_info "some context info"
set encrypted [::tink::hybrid::encrypt $new_hybrid_test_public_keyset_handle $plaintext $context_info]
set decrypted [::tink::hybrid::decrypt $new_hybrid_test_private_keyset_handle $encrypted $context_info]
puts new_hybrid,decrypted=$decrypted
::tink::unregister_keyset $new_hybrid_test_private_keyset_handle
::tink::unregister_keyset $new_hybrid_test_public_keyset_handle