Skip to content

Commit

Permalink
Fix: configure the correct SM4 encryption algorithm (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
SheepSheepChen authored Aug 17, 2023
1 parent ebe57ab commit 5ef2735
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
4 changes: 4 additions & 0 deletions sdks/blue-krill/CHANGE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Change logs

### 2.0.2

- Fix: configure the correct SM4 encryption algorithm

### 2.0.1

- Feature: EncryptField supports SM4 encryption algorithm
Expand Down
3 changes: 2 additions & 1 deletion sdks/blue-krill/blue_krill/encrypt/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ class SM4CTR:
def __init__(self, secret_key: Optional[bytes] = None):
self.secret_key = secret_key or get_default_secret_key()
self.cipher = get_symmetric_cipher(
common={"key": secret_key},
common={"key": self.secret_key},
cipher_type=constants.SymmetricCipherType.SM4.value,
cipher_options={
constants.SymmetricCipherType.SM4.value: SM4SymmetricOptions(mode=constants.SymmetricMode.CTR)
},
Expand Down
2 changes: 1 addition & 1 deletion sdks/blue-krill/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "blue-krill"
version = "2.0.1"
version = "2.0.2"
description = "Tools and common packages for blueking paas"
license = "Apache License 2.0"
readme = "README.md"
Expand Down
4 changes: 2 additions & 2 deletions sdks/blue-krill/tests/test_encrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_sm4cipher_encrypt(self):
encrypt_handler = EncryptHandler(encrypt_cipher_type='SM4CTR', secret_key=Fernet.generate_key())
text = random_string(10)
encrypted = encrypt_handler.encrypt(text)
assert encrypted.startswith("sm4ctr")
assert encrypted.startswith("sm4ctr$")
assert encrypt_handler.decrypt(encrypted) == text

def test_mixcipher_encrypt(self):
Expand All @@ -55,7 +55,7 @@ def test_sm4cipher_encrypt(self):
encrypt_handler = EncryptHandler()
text = random_string(10)
encrypted = encrypt_handler.encrypt(text)
assert encrypted.startswith("sm4ctr")
assert encrypted.startswith("sm4ctr$")
assert encrypt_handler.decrypt(encrypted) == text


Expand Down

0 comments on commit 5ef2735

Please sign in to comment.