RNCryptor-python icon indicating copy to clipboard operation
RNCryptor-python copied to clipboard

Allow to en/decrypt bytes

Open dwt opened this issue 4 years ago • 2 comments

Hi there,

while trying to use this project, I've stumbled on the issue that it is not possible to use RNCryptor to en-/decrypt bytes().

Specifically here the result is always cast to str().

My workaround was to define a custom subclass that patches out this to_str() call like this:

class BytesCrypter(rncryptor.RNCryptor):
    def post_decrypt_data(self, data):
        # super call normalizes return value to str() which breaks us
        data = data[:-rncryptor.bord(data[-1])]
        return data

Since encrypt() already supports byte data, it would be very helpful if decrypt() could support that too. I'd imagine that could be achieved ether with a keyword (only) argument like this:

def decrypt(self, data, password, post_process=to_str):
    # ...

I would like the encryption interface to work solely on bytes if possible, especially on python 3 as that would be much more uniiversal, but I'm not sure if that api breakage would be ok - hence the post_process argument idea.

dwt avatar Mar 24 '21 11:03 dwt

See #8, but I believe we should be able to release a fix to this as long as we bump the major version number (i.e. following PEP 440).

@ykalchevskiy, are you still maintaining this repo, or would you prefer I look at it?

rnapier avatar Mar 24 '21 18:03 rnapier

:-) Well, what you recommend there, is actually exactly what I did. :-)

Looking forward to your fix!

dwt avatar Mar 24 '21 18:03 dwt