3

How do you use pycrypto with GAP?

It says here that it does not support the latest version. Does that mean that I have to use the version pointed by them ?

I tried this but, when I execute setup.py I get the error src/MD2.c:15:20: fatal error: Python.h: No such file or directory compilation terminated.
error: command 'gcc' failed with exit status 1

Taras
  • 1,023
  • 8
  • 17
coredump
  • 3,017
  • 6
  • 35
  • 53
  • probably you should use the correct tag google-app-engine instead of google-apps-script to get an answer? – Taifun Sep 20 '12 at 01:38

3 Answers3

4

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.

mjibson
  • 16,852
  • 8
  • 31
  • 42
  • I added the the pycrypto version 2.6 . When I run it local it works, when I deploy It gives me a server error when accessing the site. – coredump Sep 20 '12 at 07:16
  • @mjibsonIt was nothing relevant, just a server 500 error. No other info. Anyway, I managed to solve the problem. I was still including another library `passlib` in a file, at that was giving the error. – coredump Sep 20 '12 at 08:35
3

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

bobobobo
  • 64,917
  • 62
  • 258
  • 363
0

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.

root
  • 76,608
  • 25
  • 108
  • 120