首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >数据加密静态加密

数据加密静态加密
EN

Stack Overflow用户
提问于 2021-10-11 05:27:38
回答 1查看 293关注 0票数 3

我的脚步声一天比一天变。我怎样才能把它改为静态的?

代码语言:javascript
复制
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))

在从数据库调用之后,我能够解密字符串,但是第二天加密的字符串发生了更改,这使我的代码失败了。我怎么能把这个冻起来?每天都要保持一根恒定的线?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-12-13 08:04:10

通过使用字节()加密密钥,我得到了解决方案,使用字节方法将密钥存储在安全配置文件或数据库中,并加密字节字符串以获得密钥。在此之后,使用任何密码方法和适当的算法对数据进行加密和掩蔽。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69521408

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档