admin
2024-04-03 d95905057a66cd7823ade2a22e1b2debfcd20220
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import base64
import ssl
 
from cryptography.hazmat.primitives import serialization, hashes
from cryptography.hazmat.primitives.asymmetric import padding, rsa
 
def decrypt_ssl():
    context = ssl.SSLContext(ssl.PROTOCOL_TLS)
 
    # 加载证书和密钥
    context.load_cert_chain(certfile='D:/文件传输/交易/接口解析/com.aiyu.kaipanla.cert.pem', keyfile='D:/文件传输/交易/接口解析/PrivateKey1.pem')
    # 使用 SSL 上下文创建一个解密器对象
    decrypter = context.decryptor()
 
    # 加密的文本字符串
    encrypted_data = b'\xb0\x1d\x96\x82\xcd\x7f\xf2Q'
 
    # 解码加密的文本
    decrypted_data = decrypter.update(encrypted_data) + decrypter.finalize()
 
    # 打印解码后的文本
    print(decrypted_data)
 
if __name__ == '__main__':
    k =[1,0]
    is_s = True if k and k[1] else False
    print(is_s)
 
if __name__ == '__main__1':
    with open("D:\\文件传输\\交易\\接口解析\\PrivateKey1.pem", "rb") as key_file:
        private_key = serialization.load_pem_private_key(
            key_file.read(),
            password=None,
        )
        print(private_key)
    with open("D:\\文件传输\\交易\\接口解析\\PublicKey.pem", "rb") as key_file:
        public_key = serialization.load_pem_public_key(
            key_file.read(),
        )
        print(public_key)
 
    content = b""
    for i in range(10):
        content += b"Hello World 123123"
 
    encrypted = public_key.encrypt(content, padding.OAEP(
        mgf=padding.MGF1(algorithm=hashes.SHA256()),
        algorithm=hashes.SHA256(),
        label=None
    ))
 
    print(encrypted)
    decrypted = private_key.decrypt(encrypted, padding.OAEP(
        mgf=padding.MGF1(algorithm=hashes.SHA256()),
        algorithm=hashes.SHA256(),
        label=None
    ))
 
    print(decrypted)