python安全攻防数据加密学习

it2024-12-24  10

python实现base64编/解码脚本

#-*- encoding:utf-8 -*- import base64 def bs64(): method = input("输入编码或者解码:") word = input("enter a string") try: if method == '编码': bs = base64.b64encode(word.encode('utf-8')) print("编码后的为:" + str(bs)) elif method == '解码': bbs = str(base64.b64decode(word), 'utf-8') print("解码后为:" + bbs) else: breakpoint() except Exception as e: print('error') if __name__ == '__main__': bs64()

AES加密解密

加密

from Cryptodome.Cipher import AES import binascii key = b'abcdefghabcdefgh' #key的长度须为8字节 text = 'ms08067.com' #被加密的数据需要为8字节的倍数 text = text + (16 - len(text) % 16) * '=' aes = AES.new(key,AES.MODE_ECB) #ECB模式 encrypto_text = aes.encrypt(text.encode()) encryptResult = binascii.b2a_hex(encrypto_text) print(text) print(encryptResult) ms08067.com===== b'51d23f9cab201da377c925ac526c4901'

解密

#解密 from Cryptodome.Cipher import AES import binascii key = b'abcdefghabcdefgh' #key的长度须为8字节 encryptResult = b'51d23f9cab201da377c925ac526c4901' aes = AES.new(key,AES.MODE_ECB) encrypto_text = binascii.a2b_hex(encryptResult) decryptResult = aes.decrypt((encrypto_text)) print(decryptResult) b'ms08067.com====='

MD5加密

from hashlib import md5 def encrype_md5(s): new_md5 = md5() #创建对象 new_md5.update(s.encode(encoding='utf-8')) return new_md5.hexdigest() if __name__ == '__main__': print(encrype_md5('ms08067.com')) 0961f18e7a720a53797aa038c9c643d1

解密网站MD5解密

最新回复(0)