I am reading a encrypted string from a file. Below is how it appears within the file.
b'E\x08JZ(D\xcfS\x1c\xa8<\xb2\xa9\xe6\xab\x9a\x0e)\xba\xf1\xd2\xd1*B\xf2\xcbI\xb0D\x89\xcaON\xb4e\x13\xa9\xbd\xa6C\xe8\x8a\xeb\x91\\\x88\rB\x96\x97\xcb\xae\xa8\xef\x98k l\xfc\xec\xe0\x9e\x19Ag\x9fp\x00yG\x8f\xb8b?\xba\xe3\xb9uw\x04\xcb\x06\xa4 \x08|\x12\x1b\x0bJ3?\xb1\xb3i\xb3\x11\x17#u\xd1\x84\x16\x8f\xc6\x06\xff\xa7\xb9\x85V\x92\xdaL\xce\xbd\xfeh\xf7(\xec\xbb\xad\x19\xf0\xe4\xcc\x1c'
Below is how I read the line from the file.
key_location = r"----.txt"
with open(key_location, "r") as key:
last_line = key.readlines()[-1] # there are multiple lines, encrypted line is last line
I must then convert the string into byte format for RSA
encrypted_key = bytes(last_line[2:-1],'utf') # I remove the b'' from the line before conversion to avoid overlap
b'E\\x08JZ(D\\xcfS\\x1c\\xa8<\\xb2\\xa9\\xe6\\xab\\x9a\\x0e)\\xba\\xf1\\xd2\\xd1*B\\xf2\\xcbI\\xb0D\\x89\\xcaON\\xb4e\\x13\\xa9\\xbd\\xa6C\\xe8\\x8a\\xeb\\x91\\\\\\x88\\rB\\x96\\x97\\xcb\\xae\\xa8\\xef\\x98k l\\xfc\\xec\\xe0\\x9e\\x19Ag\\x9fp\\x00yG\\x8f\\xb8b?\\xba\\xe3\\xb9uw\\x04\\xcb\\x06\\xa4 \\x08|\\x12\\x1b\\x0bJ3?\\xb1\\xb3i\\xb3\\x11\\x17#u\\xd1\\x84\\x16\\x8f\\xc6\\x06\\xff\\xa7\\xb9\\x85V\\x92\\xdaL\\xce\\xbd\\xfeh\\xf7(\\xec\\xbb\\xad\\x19\\xf0\\xe4\\xcc\\x1c'
Above is the output of "print(encrypted_key)"
When I try to run
decryption_key = rsa.decrypt(encrypted_key,private_key)
It outputs "rsa.pkcs1.DecryptionError: Decryption failed"
I know for a fact that this is because encrypted_key has additional "\", it should be just one "\" like the appearance in file.
Question: how to I format encrypted_key to look like string in file "one \".