You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
601 B
Python
22 lines
601 B
Python
# -*- coding: utf-8 -*-
|
|
from M2Crypto import RSA
|
|
from M2Crypto import BIO
|
|
from binascii import a2b_hex, b2a_hex
|
|
|
|
def load_pub_key_string(string):
|
|
bio = BIO.MemoryBuffer(string)
|
|
return RSA.load_pub_key_bio(bio)
|
|
|
|
def block_data(texts, block_size):
|
|
for i in range(0, len(texts), block_size):
|
|
yield texts[i:i + block_size]
|
|
|
|
def decrypt(publick_key, texts):
|
|
plaintext = b""
|
|
block_size = 256
|
|
|
|
for text in block_data(a2b_hex(texts), block_size):
|
|
current_text = publick_key.public_decrypt(text, RSA.pkcs1_padding)
|
|
plaintext += current_text
|
|
|
|
return plaintext |