Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compatibility issues between python2 and python3 #6

Open
lucaclivio opened this issue Mar 11, 2019 · 0 comments
Open

compatibility issues between python2 and python3 #6

lucaclivio opened this issue Mar 11, 2019 · 0 comments

Comments

@lucaclivio
Copy link

lucaclivio commented Mar 11, 2019

I want be able to encrypt something with python2 and decrypt it with python3 and viceversa, I was expecting to see the encrypted text independent from the version of python used but something went wrong. Let's take this script:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys,os,os.path,hashlib,pprp,pprp.config,base64

def trans(text):
    return text.encode('utf-8') if sys.version_info[0] >= 3 else text

passphrase = trans('passwordò')
salt = trans('salt')
key_size = 32
data = trans("papà")
print(data.decode('utf-8') if sys.version_info[0] >= 3 else data)

key = pprp.pbkdf2(passphrase, salt, key_size)

# Encrypt.
sg = pprp.data_source_gen(data)
eg = pprp.rjindael_encrypt_gen(key, sg)
encrypted = pprp.encrypt_sink(eg)
print(base64.b64encode(encrypted))
# Decrypt.
sg = pprp.data_source_gen(encrypted)
dg = pprp.rjindael_decrypt_gen(key, sg)
decrypted = pprp.decrypt_sink(dg)
print(decrypted.decode('utf-8') if sys.version_info[0] >= 3 else decrypted)

This piece of software is taken from your example2 test code. I simply substituted the encoding with ASCII with UTF-8 to be able to cope with different encoding, but nothing changes with ASCII.
If you run this script with python2 or python3 the script works but differently: the two produce different encoded strings, so the two are not compatible with each other

luca@ictvt224:~$ python test_pprp.py 
papà
xQoR0CIEWbHhliKukN1CrA==
papà
luca@ictvt224:~$ python3 test_pprp.py 
papà
b'jK8D0w7bXKt3o11uJlyeGQ=='
papà

How am I wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant