Ego*_*rov 6 python security python-3.x
我发现了同样的问题.但PyCrypto并没有在python 3.6.5和3.7.0上安装.
所以,我实现了某种类似Gronsfeld的密码.我知道,这很糟糕,但我可以简单地用密码加密和解密字符串
def encrypt(string, password):
int_list = []
password_len = len(password)
for cnt, sym in enumerate(string):
password_sym = password[cnt % password_len]
int_list.append(ord(sym)-ord(password_sym))
return int_list
# got some list which contain mine key to Todoist api, yes, this can be bruteforced, but same as any other API key
>>> [-20, -20, -50, -14, -61, -54, 2, 0, 32, 27, -51, -21, -54, -53, 4, 3, 29, -14, -51, 29, -10, -6, 1, 4, 28,
29, -55, -17, -59, -42, 2, 50, -13, -14, -52, -15, -56, -59, -44, 4]
def decrypt(int_list, password):
output_string = ""
password_len = len(password)
for cnt, numb in enumerate(int_list):
password_sym = password[cnt % password_len]
output_string += chr(numb+ord(password_sym))
return output_string
Run Code Online (Sandbox Code Playgroud)
那么,如何正确地做到这一点?
Sat*_*gan 12
Cryptography是一个积极开发的库,提供加密配方和基元.它支持Python 2.6-2.7,Python 3.3+和PyPy.
安装
$ pip install cryptography
Run Code Online (Sandbox Code Playgroud)
使用高级对称加密配方的示例代码:
from cryptography.fernet import Fernet
key = Fernet.generate_key()
cipher_suite = Fernet(key)
cipher_text = cipher_suite.encrypt(b"A really secret message. Not for prying eyes.")
plain_text = cipher_suite.decrypt(cipher_text)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5122 次 |
| 最近记录: |