pycryptodome rsa encrypt

Solutions on MaxInterview for pycryptodome rsa encrypt by the best coders in the world

showing results for - "pycryptodome rsa encrypt"
Lya
04 Jan 2018
1>>> from Crypto.Cipher import PKCS1_v1_5
2>>> from Crypto.PublicKey import RSA
3>>> from Crypto.Hash import SHA
4>>>
5>>> message = b'To be encrypted'
6>>> h = SHA.new(message)
7>>>
8>>> key = RSA.importKey(open('pubkey.der').read())
9>>> cipher = PKCS1_v1_5.new(key)
10>>> ciphertext = cipher.encrypt(message+h.digest())
11
Chiara
15 May 2016
1from Crypto.Cipher import AES
2from Crypto.Random import get_random_bytes
3
4key = get_random_bytes(16)
5cipher = AES.new(key, AES.MODE_EAX)
6ciphertext, tag = cipher.encrypt_and_digest(data)
7
8file_out = open("encrypted.bin", "wb")
9[ file_out.write(x) for x in (cipher.nonce, tag, ciphertext) ]
10file_out.close()
11