温馨提示×

APP数据如何加密

九三
285
2021-02-09 11:06:58
栏目: 网络安全

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))

0