def test_encrypts_and_decrypts_data(self): raw_data = bytearray("test", "utf-8") key_pair1 = VirgilKeyPair.generate(VirgilKeyPair.Type_FAST_EC_ED25519) key_pair2 = VirgilKeyPair.generate(VirgilKeyPair.Type_FAST_EC_ED25519) cipher = VirgilChunkCipher() cipher.addKeyRecipient(bytearray("1", "utf-8"), key_pair1.publicKey()) cipher.addKeyRecipient(bytearray("2", "utf-8"), key_pair2.publicKey()) encrypt_input_stream = io.BytesIO(raw_data) encrypt_output_stream = io.BytesIO() encrypt_source = VirgilStreamDataSource(encrypt_input_stream) encrypt_sink = VirgilStreamDataSink(encrypt_output_stream) cipher.encrypt(encrypt_source, encrypt_sink) encrypted_data = encrypt_output_stream.getvalue() decrypt_input_stream = io.BytesIO(encrypted_data) decrypt_output_stream = io.BytesIO() decrypt_source = VirgilStreamDataSource(decrypt_input_stream) decrypt_sink = VirgilStreamDataSink(decrypt_output_stream) cipher = VirgilChunkCipher() cipher.decryptWithKey(decrypt_source, decrypt_sink, bytearray("1", "utf-8"), key_pair1.privateKey()) decrypted_data1 = decrypt_output_stream.getvalue() self.assertEqual(raw_data, bytearray(decrypted_data1)) decrypt_input_stream = io.BytesIO(encrypted_data) decrypt_output_stream = io.BytesIO() decrypt_source = VirgilStreamDataSource(decrypt_input_stream) decrypt_sink = VirgilStreamDataSink(decrypt_output_stream) cipher.decryptWithKey(decrypt_source, decrypt_sink, bytearray("2", "utf-8"), key_pair2.privateKey()) decrypted_data2 = decrypt_output_stream.getvalue() self.assertEqual(raw_data, bytearray(decrypted_data2))
def test_encrypts_and_decrypts_private_key(self): password = bytearray("test", "utf-8") key_pair = VirgilKeyPair.generate(VirgilKeyPair.Type_FAST_EC_ED25519) encrypted_private_key = VirgilKeyPair.encryptPrivateKey( key_pair.privateKey(), password) decrypted_private_key = VirgilKeyPair.decryptPrivateKey( encrypted_private_key, password) self.assertEqual(key_pair.privateKey(), decrypted_private_key)
def test_encrypts_and_decrypts_data(self): raw_data = bytearray("test", "utf-8") key_pair1 = VirgilKeyPair.generate(VirgilKeyPair.Type_FAST_EC_ED25519) key_pair2 = VirgilKeyPair.generate(VirgilKeyPair.Type_FAST_EC_ED25519) cipher = VirgilCipher() cipher.addKeyRecipient(bytearray("1", "utf-8"), key_pair1.publicKey()) cipher.addKeyRecipient(bytearray("2", "utf-8"), key_pair2.publicKey()) encrypted_data = cipher.encrypt(raw_data) cipher = VirgilCipher() decrypted_data1 = cipher.decryptWithKey(encrypted_data, bytearray("1", "utf-8"), key_pair1.privateKey()) self.assertEqual(raw_data, bytearray(decrypted_data1)) decrypted_data2 = cipher.decryptWithKey(encrypted_data, bytearray("2", "utf-8"), key_pair2.privateKey()) self.assertEqual(raw_data, bytearray(decrypted_data2))
def test_signs_and_verifies_data(self): raw_data = bytearray("test", "utf-8") key_pair = VirgilKeyPair.generate(VirgilKeyPair.Type_FAST_EC_ED25519) signer = VirgilSigner() signature = signer.sign(raw_data, key_pair.privateKey()) signer = VirgilSigner() is_valid = signer.verify(raw_data, signature, key_pair.publicKey()) self.assertTrue(is_valid)
def test_signs_and_verifies_data(self): raw_data = bytearray("test", "utf-8") key_pair = VirgilKeyPair.generate(VirgilKeyPair.Type_FAST_EC_ED25519) input_stream = io.BytesIO(raw_data) source = VirgilStreamDataSource(input_stream) signer = VirgilStreamSigner() signature = signer.sign(source, key_pair.privateKey()) input_stream = io.BytesIO(raw_data) source = VirgilStreamDataSource(input_stream) signer = VirgilStreamSigner() is_valid = signer.verify(source, signature, key_pair.publicKey()) self.assertTrue(is_valid)
def test_generates_keys(self): key_pair = VirgilKeyPair.generate(VirgilKeyPair.Type_FAST_EC_ED25519) self.assertTrue(key_pair.publicKey()) self.assertTrue(key_pair.privateKey())
def test_extracts_public_key(self): key_pair = VirgilKeyPair.generate(VirgilKeyPair.Type_FAST_EC_ED25519) extracted_public_key = VirgilKeyPair.extractPublicKey( key_pair.privateKey(), []) self.assertEqual(key_pair.publicKey(), extracted_public_key)
def test_converts_keys_to_der(self): key_pair = VirgilKeyPair.generate(VirgilKeyPair.Type_FAST_EC_ED25519) self.assertTrue(VirgilKeyPair.publicKeyToDER(key_pair.publicKey())) self.assertTrue(VirgilKeyPair.privateKeyToDER(key_pair.privateKey()))