python aes解密腳本

環境:windows python2.7

代碼: 

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import sys
reload(sys)
sys.setdefaultencoding('utf-8')
import base64
from Crypto.Cipher import AES


# 密鑰(key), 密斯偏移量(iv) CBC模式加密


def AES_Decrypt(key, data):
    vi = '1234567890123456'
    data = data.encode('utf8')
    encodebytes = base64.b64decode(data)
    # 將加密數據轉換位bytes類型數據
    cipher = AES.new(key.encode('ASCII'), AES.MODE_CBC, vi.encode('utf8'))
    text_decrypted = cipher.decrypt(encodebytes)


    # 去補位
    text_decrypted = text_decrypted.decode('utf8')
    return text_decrypted


key = 'EaRncVfLgIPMaygA'
data = 'kt1zBVG4Om1rVxe2ISqt1WFZ+tWvgNV3QygfrSlFRjI='
text_decrypted = AES_Decrypt(key, data)
print(text_decrypted)


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章