def test_encrypt_decrypt(self): rsa = lib_rsa.Rsa(public_key=PUBLIC_KEY, private_key=PRIVATE_KEY, passphrase=PRIVATE_KEY_PASS) enc = rsa.encrypt(TXT_DEC) dec = rsa.decrypt(enc) assert (dec == TXT_DEC)
def __init__(self, config, passphrase=None): Connection.__init__(self) if not isinstance(config, Config): raise ValueError('Config must be an instance of Config()') public_key = private_key = None if config.public_key: with open(config.public_key, 'rb') as file: public_key = file.read() if config.private_key: with open(config.private_key, 'rb') as file: private_key = file.read() self.aes_dir = config.aes_dir self.rsa = lib_rsa.Rsa(private_key=private_key, public_key=public_key, passphrase=passphrase) self.aes, self.aes_filename = self.__get_aes_info()
def test_generate_keypair_with_wrong_pass(fs): private, public = lib_rsa.generate_keypair(modulo=1024, passphrase='txt') with pytest.raises(ValueError): lib_rsa.Rsa(public_key=public, private_key=private, passphrase='wrong')
def test_generate_keypair_with_pass(fs): private, public = lib_rsa.generate_keypair(modulo=1024, passphrase='txt') lib_rsa.Rsa(public_key=public, private_key=private, passphrase='txt')
def test_generate_keypair_no_pass(fs): private, public = lib_rsa.generate_keypair(modulo=1024) lib_rsa.Rsa(public_key=public, private_key=private)
def test_can_decrypt(self): rsa = lib_rsa.Rsa(private_key=PRIVATE_KEY, passphrase=PRIVATE_KEY_PASS) assert (rsa.can_decrypt()) rsa = lib_rsa.Rsa() assert (not rsa.can_decrypt())
def test_can_encrypt(self): rsa = lib_rsa.Rsa(public_key=PUBLIC_KEY) assert (rsa.can_encrypt()) rsa = lib_rsa.Rsa() assert (not rsa.can_encrypt())
def test_decrypt_no_private_key_raises_value_error(self): rsa = lib_rsa.Rsa(public_key=PUBLIC_KEY) with pytest.raises(ValueError): rsa.decrypt(TXT_ENC)
def test_encrypt_no_public_key_raises_value_error(self): rsa = lib_rsa.Rsa(private_key=PRIVATE_KEY, passphrase=PRIVATE_KEY_PASS) with pytest.raises(ValueError): rsa.encrypt(TXT_DEC)
def test_decrypt(self): rsa = lib_rsa.Rsa(private_key=PRIVATE_KEY, passphrase=PRIVATE_KEY_PASS) dec = rsa.decrypt(TXT_ENC) assert (dec == TXT_DEC)