我的脚步声一天比一天变。我怎样才能把它改为静态的?
码
from Crypto.Cipher import AES
import pandas as pd
import mysql.connector
myconn = mysql.connector.connect(host="######", user="##", password="######", database="#######")
query = """SELECT * from table """
df = pd.read_sql(query, myconn) #getting hexidigit back from the SQL server after dumping the ecrypted data into the database
def resize_length(string):
#resizes the String to a size divisible by 16 (needed for this Cipher)
return string.rjust((len(string) // 16 + 1) * 16)
def encrypt(url, cipher):
# Converts the string to bytes and encodes them with your Cipher
cipherstring = cipher.encrypt(resize_length(url).encode())
cipherstring = "".join("{:02x}".format(c) for c in cipherstring)
return cipherstring
def decrypt(text, cipher):
# Converts the string to bytes and decodes them with your Cipher
text = bytes.fromhex(text)
original_url = cipher.decrypt(text).decode().lstrip()
return original_url
# It is important to use 2 ciphers with the same information, else the system breaks
# Define the Cipher with your data (Encryption Key and IV)
cipher1 = AES.new('This is a key123', AES.MODE_CBC, 'This is an IV456')
cipher2 = AES.new('This is a key123', AES.MODE_CBC, 'This is an IV456')
message = df['values'][4]
eypt = encrypt(message, cipher1)
print(decrypt(eypt, cipher2))在从数据库调用之后,我能够解密字符串,但是第二天加密的字符串发生了更改,这使我的代码失败了。我怎么能把这个冻起来?每天都要保持一根恒定的线?
发布于 2021-12-13 08:04:10
通过使用字节()加密密钥,我得到了解决方案,使用字节方法将密钥存储在安全配置文件或数据库中,并加密字节字符串以获得密钥。在此之后,使用任何密码方法和适当的算法对数据进行加密和掩蔽。
https://stackoverflow.com/questions/69521408
复制相似问题