Skip to content

Commit

Permalink
Switch to urlsafe base62 for aes tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
onejgordon committed Feb 13, 2018
1 parent 2e256d8 commit 5dc1148
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ client_secret.json
yarn-error.log
package-lock.json
yarn.lock
genzai-app-*.json
6 changes: 3 additions & 3 deletions common/aes_cypher.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import base64
import base62
from Crypto.Cipher import AES
from Crypto import Random

Expand All @@ -18,10 +18,10 @@ def encrypt(self, raw):
raw = self.pad(raw)
iv = Random.new().read(AES.block_size)
cipher = AES.new(self.key, AES.MODE_CBC, iv)
return base64.b64encode(iv + cipher.encrypt(raw))
return base62.encodebytes(iv + cipher.encrypt(raw))

def decrypt(self, enc):
enc = base64.b64decode(enc)
enc = base62.decodebytes(enc)
iv = enc[:16]
cipher = AES.new(self.key, AES.MODE_CBC, iv)
return self.unpad(cipher.decrypt(enc[16:]))
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ oauth2client==3.0.0
# google-cloud-bigquery==0.21.0
google_api_python_client==1.5.1
GoogleAppEngineCloudStorageClient==1.9.22.1
pyjwt==1.4.1
pyjwt==1.4.1
pybase62

0 comments on commit 5dc1148

Please sign in to comment.