# 客户端代码
text = 'hello server!'
# 随机生成aes的密钥
aes_key = get_random_bytes(16)
aes_cipher = AESCipher(aes_key)
rsa_cipher = RSACipher()
# 使用aes密钥对数据进行加密
encrypt_text = aes_cipher.encrypt(text)
# 使用客户端私钥对aes密钥签名
signature = rsa_cipher.sign(Config.CLIENT_PRIVATE_KEY, aes_key)
# 使用服务端公钥加密aes密钥
encrypt_key = rsa_cipher.encrypt(Config.SERVER_PUBLIC_KEY, aes_key)
# 服务端代码
# 模拟接收到客户端的加密aes密钥、签名、加密的密文
encrypt_key = 'Ny7nndkNalyCX8soyOXVELsxcWuVjsMJGXGpMRph2Tj9TRn8h9ClVl6q0OcSDy0XTSmb52fl30I4kqS4m7sE+NpOUDso7X+B1YNUFe/Pop+M3aFxi7atxI9gW+6hQUJSwuO4id1gTcG+m4p/W8eFmFwUdbUN6U4mqLetcJfqHQk='
signature = '2e6b/uths9iBuvAk41CRZ8OQbcixcfmDmTQ2ym4zNS0YC0Qb4ep5nROdGOoFVnkrDOBaZ5mbzcBFGIFEgupoCcOGF9dZqh/hODdW7dPx6uXczg5gltHUO8F/dkXORcmMgyjLrhh3BcKe5/0ca6VdpLlXaYzJQBERvgeMSm467NE='
encrypt_text = 'a7owrQShmjXZZ003DBPyNQ=='
# 使用服务端私钥对加密后的aes密钥解密
aes_key = rsa_cipher.decrypt(Config.SERVER_PRIVATE_KEY, encrypt_key)
# 使用客户端公钥验签
result = rsa_cipher.verify(Config.CLIENT_PUBLIC_KEY, aes_key, signature)
# 使用aes私钥解密密文
aes_cipher = AESCipher(aes_key)
decrypt_text = aes_cipher.decrypt(encrypt_text)
Client public key(PKCS#8)
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDv/LnAoDkyewwjwqwgi9VSg51F
+tUJ8cGwL6Rqdf5ZXrRCHI1KLjOxdFbzB81YjS76cOzezQRz2vuYDo7OvLfYSjFI
fmukUxN+EliKkg0TwswylVroLBW9OKN70Zd62dc+gfkA3Vu8cDoRKz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