小编Ahm*_*ama的帖子

如何在 pycryptodom 中使用 ECC 加密消息

我正在使用混合加密(RSA+AES),但长度很大,现在我想使用 ECC 而不是 RSA,但在 pycryptodom 中没有实现。这是我的 RSA 代码

def generate_keys():
    key = RSA.generate(1024)
    private_key = key.exportKey(format='PEM', pkcs=8, 
                  protection="scryptAndAES128-CBC")
    f = open("private_key.pem", "wb")
    f.write(private_key)
    public_key = key.publickey().exportKey('PEM')
    f = open("public_key.pem", "wb")
    f.write(public_key)
    f.close()

def encrypt(username, msg):
    #get the reciever's public key
    f = open("{}.pem".format(username)) # a.salama.pem
    recipient_key = RSA.import_key(f.read())
    f.close()

    # Encrypt the session key with the reciever's public RSA key
    cipher_rsa = PKCS1_OAEP.new(recipient_key)

    # Encrypt the data with the AES session key
    session_key = get_random_bytes(16)

    cipher_aes = AES.new(session_key, AES.MODE_EAX)
    ciphertext, …
Run Code Online (Sandbox Code Playgroud)

python encryption pycrypto

5
推荐指数
1
解决办法
9770
查看次数

标签 统计

encryption ×1

pycrypto ×1

python ×1