APP数据如何加密

1233
2021/2/9 11:06:58
栏目: 网络安全
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

APP数据如何加密

对APP数据进行加密的方法有以下几种

1.MD5加密

使用方法:

import hashlib

s = '你好,世界!'

s = s.encode("utf-8")

m = hashlib.md5()

m.update(s)

psw = m.hexdigest()

2.base64加密

使用方法:

import base64

s = '你好,世界!'

s = s.encode("utf-8")

s1 = base64.encodestring(s)

s2 = base64.decodestring(s1).decode("utf-8")

print("原始数据:",s2)

print("base64:",s1)

3.bcrypt加密

使用方法:

import bcrypt

paswd = "YUjun"

password = paswd.encode("utf-8")

hashed = bcrypt.hashpw(password,bcrypt.gensalt())

print(password)

print(hashed)

if bcrypt.hashpw(password,hashed) == hashed:

print("It maches!")

else:

print("It does not match:(")

4.AES加密

使用方法:

from Crypto.Cipher import AES

obj = AES.new('This is a key123', AES.MODE_CBC, 'This is an IV456')

message = "The answer is no"

ciphertext = obj.encrypt(message)

print(ciphertext)

obj2 = AES.new('This is a key123', AES.MODE_CBC, 'This is an IV456')

print(obj2.decrypt(ciphertext))

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: web表单数据如何加密