Encrypt PackedByteArray with String in Godot 4

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By MintSoda

Hi, I used to create two files for every saved game in 3.x. One is my save data, which is encrypted by a simple string password. It is created by save_encrypted_pass(path, password) from a ConfigFile. The other is a screenshot.

Now in Godot 4 beta, I’m now able to use ZIPPacker to pack the screenshot and save data together as one single zip file. And ZIPPacker.write_file only supports PackedByteArray. I use config_file.encode_to_text().to_utf_buffer() to convert it to PackedByteArray. But how do I encrypt PackedByteArray?

I know CryptoKey. However, it seems to support only RSA encryption, not simple a string like save_encrypted_pass does.

I could save it to disk then use FileAccess.open_encrypted_with_pass(path, FileAccess.WRITE, password), then load it as PackedByteArray. But I don’t want to do unnecessary IOs.

:bust_in_silhouette: Reply From: MintSoda

OK, I figured it out. Use AESContext.
But it’s so deeply hidden?
Also, save_encrypted_pass uses AES256, but it’s not mentioned anywhere in docs.
Might need to submit an issue about this.