MCPcopy
hub / github.com/1Panel-dev/MaxKB / rsa_long_encrypt

Function rsa_long_encrypt

apps/common/utils/rsa_util.py:100–124  ·  view source on GitHub ↗

超长文本加密 :param message: 需要加密的字符串 :param public_key 公钥 :param length: 1024bit的证书用100, 2048bit的证书用 200 :return: 加密后的数据

(message, public_key: str | None = None, length=200)

Source from the content-addressed store, hash-verified

98
99
100def rsa_long_encrypt(message, public_key: str | None = None, length=200):
101 """
102 超长文本加密
103
104 :param message: 需要加密的字符串
105 :param public_key 公钥
106 :param length: 1024bit的证书用100, 2048bit的证书用 200
107 :return: 加密后的数据
108 """
109 if public_key is None:
110 public_key = get_key_pair().get('key')
111
112 cipher = _get_encrypt_cipher(public_key)
113
114 if len(message) <= length:
115 result = base64.b64encode(cipher.encrypt(message.encode('utf-8')))
116 else:
117 rsa_text = []
118 for i in range(0, len(message), length):
119 cont = message[i:i + length]
120 rsa_text.append(cipher.encrypt(cont.encode('utf-8')))
121 cipher_text = b''.join(rsa_text)
122 result = base64.b64encode(cipher_text)
123
124 return result.decode()
125
126
127@lru_cache(maxsize=2)

Callers 4

editMethod · 0.90
editMethod · 0.90
insertMethod · 0.90

Calls 6

_get_encrypt_cipherFunction · 0.85
decodeMethod · 0.80
get_key_pairFunction · 0.70
getMethod · 0.45
encodeMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected