

Message1 = "".format(ciphertext, signature) messes up the (byte) strings, and when the message is split back ( message2 = message2.split("|")) the results are different from ciphertext and signature. Return rsa.verify(message.encode('utf8'), signature, key,) = 'SHA-1'ĪPubKey, APrivKey, BPubKey, BPrivKey = loadKeys() Return rsa.sign(message.encode('utf8'), key, 'SHA-1') Return rsa.decrypt(ciphertext, key).decode('utf8') Return rsa.encrypt(message.encode('utf8'), key) Return APubKey, APrivKey, BPubKey, BPrivKey With open('keys/BPrivKey.pem', 'rb') as p:īPrivKey = _pkcs1(p.read()) With open('keys/BPubKey.pem', 'rb') as p:īPubKey = _pkcs1(p.read()) With open('keys/APrivKey.pem', 'rb') as p:ĪPrivKey = _pkcs1(p.read()) With open('keys/APubKey.pem', 'rb') as p:ĪPubKey = _pkcs1(p.read()) With open('keys/BPrivKey.pem', 'wb') as p: With open('keys/BPubKey.pem', 'wb') as p: With open('keys/APrivKey.pem', 'wb') as p: With open('keys/APubKey.pem', 'wb') as p: (publicKey, privateKey) = rsa.newkeys(1024)

n = p * qĬalculate ϕ(n) function ( Euler’s totient), that is, how many coprime with n are in range (1, n). This number n becomes modulus in both keys. # For now, we assign two primes to p and qįind n – the product of these numbers.

Python implementation of the RSA Encryption Algorithm.Ĭhoose two prime numbers (p, q), such as p is not equal to q.
