encrytString in Panda3D 1.10

Is encrypt/decryptString still supported in 1.10?

Previously I have a project running on Panda 1.9 and Python 2.7.
I am trying to upgrade it to Panda 1.10 and Python 3.7, and I have encounter this encryption error that I couldn’t get pass…

from panda3d.core import *


Traceback (most recent call last):
File “”, line 1, in
UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xdc in position 8: invalid continuation byte

Is there a reason for using encryptString instead of importing and using hashlib?

It is broken in Python 3, because it returns str instead of bytes. Have you checked if there is an issue report filed on this at GitHub yet?

was using encryptString for app data in Panda1.9.
If i switch to hashlib, will all the app data that was previously encrypted with encryptString be lost or are both of them compatible with each other?

ah ha… ok. I have just reported this to the Github issue page.

While I do not know how encryptString works, you can always use an older version of Panda to get your decrypted data and then re-encrypt them with hashlib.

basically i have an application and i uses encryptString to protect some app data stored on client’s computer. The data are converted back with decryptString to useful app data when the clients open the app again.

I have just check on hashlib and seems hashlib is a one way thing… so I am not sure it’s applicable in this case…

and regarding the solution to use older version on Panda to decrypt and then encrypt back seems infeasible as the data are stored on different clients’ computers…

You are right that this is a one way thing so hashlib is not what you are looking for, and given that you already have data stored on different clients’ computers, I guess you really need to use the same algorithm as the one implemented at Panda’s encryptString… Perhaps it is best then you find the algorithm from a working version and re-implement it in modern Panda, use an older Panda version that still works or wait for a fix.

I found out that encryptStream does work, so you can use this version of encryptString instead as a workaround:

from panda3d.core import *

def encryptString(source, password, algorithm="", key_length=-1, iteration_count=-1):
    src = StringStream(source.encode('utf-8'))
    dst = StringStream()
    if not encryptStream(src, dst, password, algorithm, key_length, iteration_count):
        return b''
    return dst.data

print(encryptString('123', 'abc'))
1 Like

I’ve checked in a fix. Link to GitHub issue for the record: