-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathtest_encryption.py
More file actions
42 lines (32 loc) · 1.33 KB
/
test_encryption.py
File metadata and controls
42 lines (32 loc) · 1.33 KB
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
# Copyright (c) Alibaba, Inc. and its affiliates.
import json
from dashscope.api_entities.encryption import Encryption
class TestEncryption:
@staticmethod
def test_get_public_keys():
pub_keys = Encryption._get_public_keys()
print(f"\nrsa:\n{json.dumps(pub_keys, indent=4, ensure_ascii=False)}")
print(f"\npublic_key_id: {pub_keys.get('public_key_id')}")
print(f"\npublic_key: {pub_keys.get('public_key')}")
@staticmethod
def test_generate_aes_secret_key(self):
key = Encryption._generate_aes_secret_key()
print(f"\nkey: {key}")
@staticmethod
def test_generate_aes_iv(self):
iv = Encryption._generate_iv()
print(f"\niv: {iv}")
@staticmethod
def test_encrypt_with_aes():
key = Encryption._generate_aes_secret_key()
iv = Encryption._generate_iv()
text = "hello world"
ciphertext = Encryption._encrypt_text_with_aes(text, key, iv)
print(f"\nciphertext: {ciphertext}")
@staticmethod
def test_encrypt_aes_key_with_rsa():
public_keys = Encryption._get_public_keys()
public_key = public_keys.get('public_key')
aes_key = Encryption._generate_aes_secret_key()
cipher_aes_key = Encryption._encrypt_aes_key_with_rsa(aes_key, public_key)
print(f"\ncipher_aes_key: {cipher_aes_key}")