Revision bd16bf3e snf-cyclades-app/synnefo/api/util.py
b/snf-cyclades-app/synnefo/api/util.py | ||
---|---|---|
31 | 31 |
# interpreted as representing official policies, either expressed |
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 |
from base64 import b64encode, b64decode |
|
34 |
from base64 import urlsafe_b64encode, b64decode |
|
35 |
from urllib import quote |
|
35 | 36 |
from hashlib import sha256 |
36 | 37 |
from logging import getLogger |
37 | 38 |
from random import choice |
... | ... | |
118 | 119 |
return s + '\x00' * npad |
119 | 120 |
|
120 | 121 |
|
121 |
def encrypt(plaintext): |
|
122 |
def stats_encrypt(plaintext):
|
|
122 | 123 |
# Make sure key is 32 bytes long |
123 |
key = sha256(settings.SECRET_KEY).digest() |
|
124 |
key = sha256(settings.CYCLADES_STATS_SECRET_KEY).digest()
|
|
124 | 125 |
|
125 | 126 |
aes = AES.new(key) |
126 | 127 |
enc = aes.encrypt(zeropad(plaintext)) |
127 |
return b64encode(enc)
|
|
128 |
return quote(urlsafe_b64encode(enc))
|
|
128 | 129 |
|
129 | 130 |
|
130 | 131 |
def get_vm(server_id, user_id, for_update=False, non_deleted=False, |
Also available in: Unified diff