, , Python. , Python Cryptography Toolkit (PyCrypt). , Python . , AES PyCrypt:
from Crypto.Cipher import AES
from urllib import quote
encryption_obj = AES.new('abcdefghijklmnop')
plain = "Testing"
mismatch = len(plain) % 16
if mismatch != 0:
padding = (16 - mismatch) * ' '
plain += padding
ciph = encryption_obj.encrypt(plain)
quoted_ciph = quote(ciph)
URL-, , GET.
, ; , encryption_obj , , URL-, :
from urllib import unquote
ciph = unquote(quoted_ciph)
plain = encryption_obj.decrypt(ciph)
: ( , ) pk . , , pk . ( , hashlib.)
- , models.py:
class Pk_lookup(models.Model):
hashed_pk = models.CharField(primary_key=True, max_length=32)
key = models.IntegerField()
, - :
import hashlib
import Pk_lookup
hash = hashlib.sha256()
hash.update(str(pk))
pk_digest = hash.digest()
lookup = Pk_lookup(hashed_pk=pk_digest,key=pk)
lookup.save()
, ; , hexdigest() digest ( ), 64.