예제 #1
0
def decrypt(encryptPassword):
    # 解密函数
    base64Decoded = base64.b64decode(encryptPassword)
    bs = AES.block_size
    unpad = lambda s: s[0:-s[-1]]
    iv = base64Decoded[:bs]
    key = base64Decoded[-32:]
    cipher = AES.new(key, AES.MODE_CBC, iv)
    originalPassword = unpad(cipher.decrypt(base64Decoded[:-32]))[bs:]
    return originalPassword
예제 #2
0
def encrypt(originalPassword):
    # 加密函数
    bs = AES.block_size
    pad = lambda s: s + (bs - len(s) % bs) * chr(bs - len(s) % bs)
    paddPassword = pad(originalPassword)
    iv = Random.OSRNG.new().read(bs)
    key = os.urandom(32)
    cipher = AES.new(key, AES.MODE_CBC, iv)
    encryptPassword = base64.b64encode(iv + cipher.encrypt(paddPassword) + key)
    return encryptPassword
예제 #3
0
 def _aes256cbc_encrypt(key, iv, plaintext):
     cipher = _AES.new(key, _AES.MODE_CBC, iv)
     ciphertext = cipher.encrypt(plaintext)
     return ciphertext
예제 #4
0
def pycrypto_aes_ctr(key, index):
    from Crypto.Cipher import AES
    from Crypto.Util import Counter
    ctr = Counter.new(128, initial_value=index)
    return AES.new(key, AES.MODE_CTR, counter=ctr)
예제 #5
0
def pycrypto_aes_ecb(key):
    from Crypto.Cipher import AES
    return AES.new(key, AES.MODE_ECB)