MCPcopy Create free account
hub / github.com/MearaY/StegaPy / __init__

Method __init__

StegaPy/util/crypto_util.py:25–42  ·  view source on GitHub ↗

初始化加密工具

(self, password, algorithm='AES128')

Source from the content-addressed store, hash-verified

23 ITER_COUNT = 7
24
25 def __init__(self, password, algorithm='AES128'):
26 """初始化加密工具"""
27 self.password = password
28 self.algorithm = algorithm.upper() if algorithm else 'AES128'
29
30 # 根据算法确定密钥长度
31 if self.algorithm == 'AES128':
32 self.key_length = 16
33 elif self.algorithm == 'AES256':
34 self.key_length = 32
35 elif self.algorithm == 'DES':
36 self.key_length = 8
37 raise ValueError("DES算法已弃用,请使用AES128或AES256")
38 else:
39 raise ValueError(f"不支持的加密算法: {algorithm}")
40
41 # 生成密钥
42 self.key = self._derive_key(password)
43
44 def _derive_key(self, password):
45 """从密码派生密钥"""

Callers

nothing calls this directly

Calls 1

_derive_keyMethod · 0.95

Tested by

no test coverage detected