0

I'm using pycryptodome to encrypt a text in this way:

 def encrypt_with_rsa(plain_text):
    #First Public Key Encryption
    cipher_pub_obj = PKCS1_OAEP.new(RSA.importKey(my_public_key))
     #encrypt
    _secret_byte_obj = cipher_pub_obj.encrypt(plain_text.encode())
 
    return _secret_byte_obj

After that, I want to divide all the string in 8 parts to get a char of each one. What I receive has this form:

b"gi?\xf4\xa8{\xe8\x1b\xec8\xd5\x96\*,t\xad\xb8D=\rCGq\xc5\xed........"

So I Try to decode that with utf-8, throws error:

** 'utf-8' codec can't decode byte 0x81 in position 5: invalid start byte **

I tried with utf-16 and 32, but no one works. I tried with latin1 too, but it ignores some parts and I don't want that. The text encoded above is changed to:

"gi?ô¨{è\x1bì8Õ\x96\*,t\xad¸D=\rCGqÅíh\x1b\x84\x0eí ó=#ÉîKô4B......"

Some parts are the same, i don´t know what type of encoding it uses, what can I do to use the encrypted text?

Will
  • 49
  • 8
  • 2
    The output of the encryption function is of **binary form** and cannot be displayed or treated like you do with a string. If you need a string encoding (e.g.for transport reasons) you need to you an encoder, the most used one is **Base64 encoding**. For later decryption it is neccessary to decode the string back to binary encoding. – Michael Fehr Jun 07 '21 at 06:14
  • *...After that, I want to divide all the string in 8 parts...* it's **not** a string. – President James K. Polk Jun 07 '21 at 12:16
  • Ty very muuuuch @MichaelFehr , that worked for me. – Will Jun 07 '21 at 15:33

0 Answers0