def sign_verify(self, private, public): with self.assertRaises(ThemisError): smessage.ssign("", "") with self.assertRaises(ThemisError): smessage.ssign(None, self.message) with self.assertRaises(ThemisError): smessage.ssign(private, "") with self.assertRaises(ThemisError): smessage.ssign(public, "message") encrypted_message = smessage.ssign(private, self.message) with self.assertRaises(ThemisError): smessage.sverify(public, "") with self.assertRaises(ThemisError): smessage.sverify(private, encrypted_message) with self.assertRaises(ThemisError): smessage.sverify(public, b"".join([b"11", encrypted_message])) decrypted_message = smessage.sverify(public, encrypted_message) self.assertEqual(self.message, decrypted_message)
def test_sign(): from pythemis import smessage b = Comrad('bez') m = Comrad('marx') z = Comrad('zuckbot') msg = b'this is cool. --bez' signed_msg = smessage.ssign(b.privkey.data, msg) print(signed_msg) verified_msg = smessage.sverify(b.pubkey.data, signed_msg) print(verified_msg)
def sign_verify(self, priv, pub): with self.assertRaises(themis_exception): smessage.ssign("", "") with self.assertRaises(TypeError): smessage.ssign(None, self.message) with self.assertRaises(themis_exception): smessage.ssign(priv, "") encrypted_message = smessage.ssign(priv, self.message) with self.assertRaises(themis_exception): smessage.sverify(pub, "") with self.assertRaises(themis_exception): smessage.sverify(pub, b"".join([b"11", encrypted_message])) decrypted_message = smessage.sverify(pub, encrypted_message) self.assertEqual(self.message, decrypted_message)
def sendall(self, message): # sign and send message self.socket.sendall(smessage.ssign(self.private_key, message))
public_key_path = sys.argv[RECIPIENT_PUBLIC_KEY] message = sys.argv[MESSAGE] with open(private_key_path, 'rb') as f: private_key = f.read() with open(public_key_path, 'rb') as f: public_key = f.read() message_encrypter = smessage.SMessage(private_key, public_key) if command == 'enc': encrypted = message_encrypter.wrap(message.encode('utf-8')) encoded = b64encode(encrypted) print(encoded.decode('ascii')) elif command == 'dec': decoded = b64decode(message.encode('utf-8')) decrypted = message_encrypter.unwrap(decoded) print(decrypted.decode('utf-8')) elif command == 'sign': encrypted = smessage.ssign(private_key, message.encode('utf-8')) encoded = b64encode(encrypted) print(encoded.decode('ascii')) elif command == 'verify': decoded = b64decode(message.encode('utf-8')) decrypted = smessage.sverify(public_key, decoded) print(decrypted.decode('utf-8')) else: print('Wrong command, use <enc | dev | sign | verify>') exit(1)