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(), )
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)
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)
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)