@@ -110,7 +110,7 @@ pip install easy_gmssl
110
110
cipher1 = test_cbc_enc.Update(plain1.encode('utf-8'))
111
111
cipher2 = test_cbc_enc.Update(plain2.encode('utf-8'))
112
112
ciphers = cipher1 + cipher2 + test_cbc_enc.Finish()
113
-
113
+
114
114
test_dec = EasySm4CBC(key.encode('utf-8'), iv.encode('utf-8'), False)
115
115
decrypted_plain1 = test_dec.Update(ciphers)
116
116
decrypted_plain = decrypted_plain1 + test_dec.Finish()
@@ -139,7 +139,7 @@ pip install easy_gmssl
139
139
cipher1 = test_gcm_enc.Update(plain1.encode('utf-8'))
140
140
cipher2 = test_gcm_enc.Update(plain2.encode('utf-8'))
141
141
ciphers = cipher1 + cipher2 + test_gcm_enc.Finish()
142
-
142
+
143
143
print('ciphers len:', len(ciphers), 'tag_len=', tag_len, 'plain len:', len(plain1 + plain2))
144
144
145
145
@@ -160,7 +160,7 @@ pip install easy_gmssl
160
160
from easy_gmssl.gmssl import SM3_HMAC_MAX_KEY_SIZE
161
161
162
162
test = EasySM3Digest()
163
-
163
+
164
164
plain1 = 'hello,world'.encode('utf-8')
165
165
plain2 = '1234567890'.encode('utf-8')
166
166
plain3 = (plain1 + plain2)
@@ -170,7 +170,7 @@ pip install easy_gmssl
170
170
print('hash value:', hash_value_2.hex())
171
171
print('hash value length in bytes:', hash_len)
172
172
173
-
173
+
174
174
plain = 'hello,world'.encode('utf-8')
175
175
print('plain hex:', plain.hex())
176
176
key = bytes([random.randint(0, 255) for _ in range(0, SM3_HMAC_MAX_KEY_SIZE)])
@@ -183,20 +183,20 @@ pip install easy_gmssl
183
183
184
184
7 . ** 随机字节流与随机字符串**
185
185
```python
186
-
186
+
187
187
from __future__ import annotations
188
188
189
189
from easy_gmssl import EasyRandomData, RandomMode
190
190
191
-
191
+
192
192
test = EasyRandomData()
193
193
ret = test.GetRandomData(20)
194
194
print(ret.hex())
195
-
195
+
196
196
test = EasyRandomData(mode = RandomMode.RandomStr)
197
197
ret = test.GetRandomData(64)
198
198
print(ret)
199
-
199
+
200
200
```
201
201
202
202
8 . ** ZUC加解密**
@@ -207,18 +207,18 @@ pip install easy_gmssl
207
207
from easy_gmssl import EasyRandomData, EasyZuc
208
208
from easy_gmssl.gmssl import ZUC_IV_SIZE , ZUC_KEY_SIZE
209
209
210
-
210
+
211
211
key = EasyRandomData().GetRandomData(ZUC_KEY_SIZE )
212
212
iv = EasyRandomData().GetRandomData(ZUC_IV_SIZE )
213
-
213
+
214
214
test = EasyZuc(key, iv)
215
215
plain1 = ' hello,world' .encode(' utf-8' )
216
216
cipher1 = test.Update(plain1)
217
217
plain2 = ' 1234567890' .encode(' utf-8' )
218
218
cipher2 = test.Update(plain2)
219
219
cipher3 = test.Finish()
220
220
221
-
221
+
222
222
test2 = EasyZuc(key, iv)
223
223
ret1 = test2.Update(cipher1)
224
224
ret2 = test2.Update(cipher2)
0 commit comments