PyCrypto on the Google App Engine development server "ImportError: Unable to import blockalgo name"

I have a function that encrypts a string using AES using PyCrypto. When I call this function in my unit tests, everything works fine. In a production environment, it works great. However, when a function is called on the GAE development server, an error occurs: "ImportError: Unable to import blockalgo name." I tested it on Windows 7 (64 bit) and Mac OS 10.5. Both led to the same error. I am using the Google App Engine with Python 2.7. What could be the problem?

app.yaml

application: xxx
version: 6
runtime: python27
api_version: 1
threadsafe: true

libraries:
- name: django
  version: "1.2"
- name: webapp2
  version: "2.3"
- name: jinja2
  version: "2.6"
- name: pycrypto
  version: "2.3"
- name: PIL
  version: "1.1.7"

builtins:
- appstats: on
- remote_api: on

inbound_services:
- mail
- warmup

Encryption Function:

def encrypt(plaintext):
    from Crypto.Cipher import AES
    import hashlib

    password = 'xxx'
    key = hashlib.sha256(password).digest()

    mode = AES.MODE_ECB
    encryptor = AES.new(key, mode)

    BLOCK_SIZE = 16
    PADDING = '{'
    pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * PADDING
    EncodeAES = lambda c, s: b58encode(c.encrypt(pad(s)))

    encrypted = EncodeAES(encryptor, plaintext)

    if len(encrypted) < 22:
        for i in range (len(encrypted), 22):
            encrypted += "_"
    return encrypted
+5
source share
1 answer

, PyCrypto, , , app.yaml. , .

+5

All Articles