def testEncryptDecrypt(self): temp_file_path = os.path.join(os.path.dirname(__file__), "data/cfile") f = open(temp_file_path, 'w') f.write("foobar") f.close() key = Crypto.generate_key("secret_key") Crypto.encrypt_file(key, temp_file_path) self.assertTrue(os.path.exists(temp_file_path + ".enc")) contents = FileManager.read_file(temp_file_path + ".enc") # TODO should do a better verification that it's actually encrypted properly self.assertTrue(contents != "foobar") os.remove(temp_file_path) Crypto.decrypt_file(key, temp_file_path + ".enc") contents = FileManager.read_file(temp_file_path) self.assertTrue(contents == "foobar") os.remove(temp_file_path) os.remove(temp_file_path + ".enc")
def __init__(self, snapfile, snapdirectory, encryption_password=None): '''initialize the snapfile @param snapfile - the path to the snapfile to create / read @param snapdirectory - the path to the directory to compress/extract @param encryption_password - the password to use in the encryption/decryption operations, if set to None encryption will be disabled @raises - MissingDirError - if the snapdirectory is invalid ''' if not os.path.isdir(snapdirectory): raise MissingDirError(snapdirectory + " is an invalid snap working directory ") self.snapfile = snapfile self.snapdirectory = snapdirectory self.encryption_password = encryption_password if not snap.osregistry.OS.is_windows() and self.encryption_password != None: self.encryption_key = Crypto.generate_key(self.encryption_password) else: self.encryption_key = None
def __init__(self, snapfile, snapdirectory, encryption_password=None): '''initialize the snapfile @param snapfile - the path to the snapfile to create / read @param snapdirectory - the path to the directory to compress/extract @param encryption_password - the password to use in the encryption/decryption operations, if set to None encryption will be disabled @raises - MissingDirError - if the snapdirectory is invalid ''' if not os.path.isdir(snapdirectory): raise MissingDirError(snapdirectory + " is an invalid snap working directory ") self.snapfile = snapfile self.snapdirectory = snapdirectory self.encryption_password = encryption_password if not snap.osregistry.OS.is_windows( ) and self.encryption_password != None: self.encryption_key = Crypto.generate_key(self.encryption_password) else: self.encryption_key = None