pycrypto and Google app engine

别来无恙 提交于 2019-12-06 00:12:16

App Engine 1.7.2, released just a few hours ago, now supports PyCrypto 2.6, the most recent version. The linked doc is likely outdated and will be updated soon. You can use it by instructing app engine to include it.

To make GAE use pycrypto, you have to add the following to your app.yaml file:

libraries:
- name: pycrypto
  version: "2.6"

Like a charm, code like

from Crypto.Cipher import AES
from Crypto import Random
class MainPage(webapp2.RequestHandler):
  def get( self ) :
    self.response.headers['Content-Type'] = 'text/plain'
    key = b'Sixteen byte key'
    iv = Random.new().read(AES.block_size)
    cipher = AES.new(key, AES.MODE_CFB, iv)
    msg = iv + cipher.encrypt(b'Attack at dawn')
    self.response.write( msg )

Should work like a charm (actually triggers a download!)

This information about what versions of what libraries are available are included here

GAP will not let you use the full version of pycrypto as it has lot of C so you can't deploy it and they will have to cut it down to what they can allow. You have to use from google.appengine.dist import use_library and then use_library('lib', 'version.'). Hopefully it is somewhat helpful.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!