I am using the following code to encrypt/decrypt only passwords. It works perfectly fine except special characters. As an example Pa$$w0rd
returns Pa1705w0rd
. Any idea how to fix it ? By the way, I have also tried PKCS1_v1_5
, but same result !
def _encrypt(self, message):
public_key = RSA.importKey(self._get_public_key())
cipher = PKCS1_OAEP.new(public_key)
encrypted_message = cipher.encrypt(message)
print(base64.b64encode(encrypted_message))
def _decrypt(self, encoded_encrypted_message):
encrypted_message = base64.b64decode(encoded_encrypted_message)
private_key = RSA.importKey(self._get_private_key())
cipher = PKCS1_OAEP.new(private_key)
print(cipher.decrypt(encrypted_message))