root/galaxy-central/eggs/Beaker-1.4-py2.6.egg/beaker/crypto/jcecrypto.py @ 3

リビジョン 3, 1.0 KB (コミッタ: kohda, 14 年 前)

Install Unix tools  http://hannonlab.cshl.edu/galaxy_unix_tools/galaxy.html

行番号 
1"""
2Encryption module that uses the Java Cryptography Extensions (JCE).
3
4Note that in default installations of the Java Runtime Environment, the
5maximum key length is limited to 128 bits due to US export
6restrictions. This makes the generated keys incompatible with the ones
7generated by pycryptopp, which has no such restrictions. To fix this,
8download the "Unlimited Strength Jurisdiction Policy Files" from Sun,
9which will allow encryption using 256 bit AES keys.
10"""
11from javax.crypto import Cipher
12from javax.crypto.spec import SecretKeySpec, IvParameterSpec
13
14import jarray
15
16# Initialization vector filled with zeros
17_iv = IvParameterSpec(jarray.zeros(16, 'b'))
18
19def aesEncrypt(data, key):
20    cipher = Cipher.getInstance('AES/CTR/NoPadding')
21    skeySpec = SecretKeySpec(key, 'AES')
22    cipher.init(Cipher.ENCRYPT_MODE, skeySpec, _iv)
23    return cipher.doFinal(data).tostring()
24
25
26def getKeyLength():
27    maxlen = Cipher.getMaxAllowedKeyLength('AES/CTR/NoPadding')
28    return min(maxlen, 256) / 8
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。