refactor: 客户端目录统一添加 kenaito-conf- 前缀
- go-client → kenaito-conf-go-client - python-client → kenaito-conf-python-client - python-client-demo → kenaito-conf-python-client-demo - nodejs-client → kenaito-conf-nodejs-client - nodejs-client-demo → kenaito-conf-nodejs-client-demo - 更新所有 README 和 package.json 中的路径引用
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import base64
|
||||
import hashlib
|
||||
|
||||
import pyaes
|
||||
|
||||
CRYPT_PREFIX = "{Cipher}"
|
||||
|
||||
|
||||
def decrypt_config(secret: str, data: str) -> str:
|
||||
if not data.startswith(CRYPT_PREFIX):
|
||||
return data
|
||||
encrypted = data[len(CRYPT_PREFIX):]
|
||||
return decrypt_with_aes(secret, encrypted)
|
||||
|
||||
|
||||
def decrypt_with_aes(key: str, data: str) -> str:
|
||||
md5_hash = hashlib.md5(key.encode()).hexdigest()
|
||||
aes_key = md5_hash[16:].encode()
|
||||
|
||||
cipher_text = base64.b64decode(data)
|
||||
|
||||
iv = b"\0" * 16
|
||||
aes_cbc = pyaes.AESModeOfOperationCBC(aes_key, iv=iv)
|
||||
plain_text = aes_cbc.decrypt(cipher_text)
|
||||
|
||||
padding = plain_text[-1]
|
||||
plain_text = plain_text[:-padding]
|
||||
|
||||
return plain_text.decode()
|
||||
Reference in New Issue
Block a user