Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pycryptodome rsa encrypt

>>> from Crypto.Cipher import PKCS1_v1_5
>>> from Crypto.PublicKey import RSA
>>> from Crypto.Hash import SHA
>>>
>>> message = b'To be encrypted'
>>> h = SHA.new(message)
>>>
>>> key = RSA.importKey(open('pubkey.der').read())
>>> cipher = PKCS1_v1_5.new(key)
>>> ciphertext = cipher.encrypt(message+h.digest())
Comment

pycryptodome rsa encrypt

from Crypto.Cipher import AES
from Crypto.Random import get_random_bytes

key = get_random_bytes(16)
cipher = AES.new(key, AES.MODE_EAX)
ciphertext, tag = cipher.encrypt_and_digest(data)

file_out = open("encrypted.bin", "wb")
[ file_out.write(x) for x in (cipher.nonce, tag, ciphertext) ]
file_out.close()
Comment

PREVIOUS NEXT
Code Example
Python :: circular queue python 
Python :: python while loop 
Python :: python string 
Python :: string template python 
Python :: python 3.8 vs 3.10 
Python :: python iterrows 
Python :: django context data 
Python :: python cast to int 
Python :: opencv python install windows 
Python :: python 3 string length 
Python :: site:*.instagram.com 
Python :: spread in python 
Python :: Facet Grid for Bar Plot with non-shared y axes (CatPlot) 
Python :: get center position of countries geopandas 
Python :: asyncioevents.py", line 504, in add_reader raise NotImplementedError 
Python :: punto1 
Python :: python Entry default text 
Python :: landscape odoo report 
Python :: pandas cummax 
Python :: python macro ensurepip py3 
Python :: pythoon 
Python :: password validation in python 
Python :: PyQt5 change keyboard/tab behaviour in a table 
Python :: select nth item from list 
Python :: menampilkan data dalam range tertentu di python 
Python :: rtdpy ncstr 
Python :: print all elements of dictionary except one in python 
Python :: hmac decrypt python 
Python :: unpad zeros from string python 
Python :: pandas show head and tail 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =