Skip to content

Commit

Permalink
cleanup long-lines
Browse files Browse the repository at this point in the history
  • Loading branch information
jobevers committed May 19, 2016
1 parent 786e95d commit 3a9333a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Keepass Protocol.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,23 @@
" data = unpadder.update(padded_data)\n",
" return data + unpadder.finalize()\n",
"\n",
"def encrypt(data, key, iv):\n",
"def getCipher(key, iv):\n",
" backend = default_backend()\n",
" cipher = Cipher(algorithms.AES(base64.b64decode(key)), modes.CBC(base64.b64decode(iv)), backend)\n",
" return Cipher(\n",
" algorithms.AES(base64.b64decode(key)),\n",
" modes.CBC(base64.b64decode(iv)),\n",
" backend\n",
" )\n",
"\n",
"def encrypt(data, key, iv):\n",
" cipher = getCipher(key, iv)\n",
" encryptor = cipher.encryptor()\n",
" p = pad(data)\n",
" res = encryptor.update(p) + encryptor.finalize()\n",
" return base64.b64encode(res)\n",
" \n",
"def decrypt(data, key, iv):\n",
" backend = default_backend()\n",
" cipher = Cipher(algorithms.AES(base64.b64decode(key)), modes.CBC(base64.b64decode(iv)), backend)\n",
" cipher = getCipher(key, iv)\n",
" decryptor = cipher.decryptor()\n",
" padded_data = decryptor.update(base64.b64decode(data)) + decryptor.finalize()\n",
" return unpad(padded_data)"
Expand Down

0 comments on commit 3a9333a

Please sign in to comment.