国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python使用PyCrypto實現AES加密功能示例

2019-11-25 16:09:46
字體:
來源:轉載
供稿:網友

本文實例講述了Python使用PyCrypto實現AES加密功能。分享給大家供大家參考,具體如下:

#!/usr/bin/env pythonfrom Crypto.Cipher import AESimport base64import os# the block size for the cipher object; must be 16, 24, or 32 for AESBLOCK_SIZE = 32# the character used for padding--with a block cipher such as AES, the value# you encrypt must be a multiple of BLOCK_SIZE in length. This character is# used to ensure that your value is always a multiple of BLOCK_SIZEPADDING = '{'# one-liner to sufficiently pad the text to be encryptedpad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * PADDING# one-liners to encrypt/encode and decrypt/decode a string# encrypt with AES, encode with base64EncodeAES = lambda c, s: base64.b64encode(c.encrypt(pad(s)))DecodeAES = lambda c, e: c.decrypt(base64.b64decode(e)).rstrip(PADDING)# generate a random secret keysecret = os.urandom(BLOCK_SIZE)# create a cipher object using the random secretcipher = AES.new(secret)# encode a stringencoded = EncodeAES(cipher, 'password')print 'Encrypted string:', encoded# decode the encoded stringdecoded = DecodeAES(cipher, encoded)print 'Decrypted string:', decoded

PS:關于加密解密感興趣的朋友還可以參考本站在線工具:

文字在線加密解密工具(包含AES、DES、RC4等):
http://tools.VeVB.COm/password/txt_encode

MD5在線加密工具:
http://tools.VeVB.COm/password/CreateMD5Password

在線散列/哈希算法加密工具:
http://tools.VeVB.COm/password/hash_encrypt

在線MD5/hash/SHA-1/SHA-2/SHA-256/SHA-512/SHA-3/RIPEMD-160加密工具:
http://tools.VeVB.COm/password/hash_md5_sha

在線sha1/sha224/sha256/sha384/sha512加密工具:
http://tools.VeVB.COm/password/sha_encode

更多關于Python相關內容感興趣的讀者可查看本站專題:《Python編碼操作技巧總結》、《Python數據結構與算法教程》、《Python Socket編程技巧總結》、《Python函數使用技巧總結》、《Python字符串操作技巧匯總》、《Python入門與進階經典教程》及《Python文件與目錄操作技巧匯總

希望本文所述對大家Python程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 葵青区| 莫力| 建湖县| 庆阳市| 古蔺县| 五指山市| 丘北县| 安福县| 金阳县| 洛浦县| 光泽县| 东至县| 孟津县| 内黄县| 浦城县| 吉木萨尔县| 中江县| 长宁区| 包头市| 中西区| 淳安县| 莎车县| 河源市| 保定市| 三门峡市| 铁岭县| 射洪县| 华亭县| 周宁县| 吉木乃县| 德格县| 阿图什市| 清新县| 许昌县| 新龙县| 丽江市| 平遥县| 上林县| 沾化县| 门源| 遂宁市|