コード例 #1
0
    def test_public_key_serializeation(self):
        crypto = Crypto(public_exponent=65537, key_size=2048)
        with open(tempfile.NamedTemporaryFile().name, 'w') as f:
            crypto.public_key_to_file(f.name)
            crypto_client = CryptoClient(f.name)

        self.assertEqual(
            crypto.public_bytes(),
            crypto_client.public_bytes(),
        )
コード例 #2
0
ファイル: main.py プロジェクト: i-anshuman/crypto
def convert():
    c = Crypto()
    input = txt.get("1.0", tk.END)
    res.delete("1.0", tk.END)
    if (operation.get() == "encrypt"):
        cipher = c.encrypt(input[0:len(input) - 1])
        res.insert("1.0", cipher)
    elif (operation.get() == "decrypt"):
        plaintext = c.decrypt(input)
        res.insert("1.0", plaintext)
コード例 #3
0
ファイル: setenv.py プロジェクト: dantam/ninja-pad-python
def make_keys(args):
    for k, v in args.auth_to_key_files_map.items():
        for val in v:
            auth_id, filename = val
            pub_file = '{}.{}'.format(filename, args.public_key_file_extension)
            crypto = Crypto(
                public_exponent=args.public_exponent,
                key_size=args.key_size,
            )
            fullpath = os.path.join(args.basedir, args.key_dir, pub_file)
            os.makedirs(os.path.dirname(fullpath), exist_ok=True)
            crypto.public_key_to_file(fullpath)
            fullpath = os.path.join(args.basedir, args.key_dir, filename)
            crypto.UNSAFE_private_key_to_file(fullpath)
コード例 #4
0
 def test_encrypt_decrypt(self):
     crypto = Crypto(public_exponent=65537, key_size=2048)
     plain = b'test'
     cipher = crypto.encrypt(plain)
     output = crypto.decrypt(cipher)
     self.assertEqual(plain, output)