diff options
author | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-04-07 22:22:18 +0200 |
---|---|---|
committer | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-04-07 22:22:18 +0200 |
commit | d2fe85670726901da627490da4155af972c1a62e (patch) | |
tree | b8931d070a51b6d8b1dabe881f54504f9d9ef6de /lib/beaker/crypto/jcecrypto.py | |
parent | Update user-agent (diff) | |
parent | fix gui (diff) | |
download | pyload-d2fe85670726901da627490da4155af972c1a62e.tar.xz |
Merge branch 'pr/n1_ardi69' into 0.4.10
Diffstat (limited to 'lib/beaker/crypto/jcecrypto.py')
-rw-r--r-- | lib/beaker/crypto/jcecrypto.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/beaker/crypto/jcecrypto.py b/lib/beaker/crypto/jcecrypto.py new file mode 100644 index 000000000..4062d513e --- /dev/null +++ b/lib/beaker/crypto/jcecrypto.py @@ -0,0 +1,30 @@ +""" +Encryption module that uses the Java Cryptography Extensions (JCE). + +Note that in default installations of the Java Runtime Environment, the +maximum key length is limited to 128 bits due to US export +restrictions. This makes the generated keys incompatible with the ones +generated by pycryptopp, which has no such restrictions. To fix this, +download the "Unlimited Strength Jurisdiction Policy Files" from Sun, +which will allow encryption using 256 bit AES keys. +""" +from javax.crypto import Cipher +from javax.crypto.spec import SecretKeySpec, IvParameterSpec + +import jarray + +# Initialization vector filled with zeros +_iv = IvParameterSpec(jarray.zeros(16, 'b')) + +def aesEncrypt(data, key): + cipher = Cipher.getInstance('AES/CTR/NoPadding') + skeySpec = SecretKeySpec(key, 'AES') + cipher.init(Cipher.ENCRYPT_MODE, skeySpec, _iv) + return cipher.doFinal(data).tostring() + +# magic. +aesDecrypt = aesEncrypt + +def getKeyLength(): + maxlen = Cipher.getMaxAllowedKeyLength('AES/CTR/NoPadding') + return min(maxlen, 256) / 8 |