コード例 #1
0
ファイル: test_rsa.py プロジェクト: domsleee/cipher
 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)
コード例 #2
0
 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()
コード例 #3
0
ファイル: test_rsa.py プロジェクト: domsleee/cipher
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')
コード例 #4
0
ファイル: test_rsa.py プロジェクト: domsleee/cipher
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')
コード例 #5
0
ファイル: test_rsa.py プロジェクト: domsleee/cipher
def test_generate_keypair_no_pass(fs):
    private, public = lib_rsa.generate_keypair(modulo=1024)
    lib_rsa.Rsa(public_key=public, private_key=private)
コード例 #6
0
ファイル: test_rsa.py プロジェクト: domsleee/cipher
 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())
コード例 #7
0
ファイル: test_rsa.py プロジェクト: domsleee/cipher
 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())
コード例 #8
0
ファイル: test_rsa.py プロジェクト: domsleee/cipher
 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)
コード例 #9
0
ファイル: test_rsa.py プロジェクト: domsleee/cipher
 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)
コード例 #10
0
ファイル: test_rsa.py プロジェクト: domsleee/cipher
 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)