公匙加密
引入
from crypto.cipher import pkcs1_v1_5 as cipher_pkcs1_v1_5
from crypto.publickey import rsa
import base64
from crypto import random
def loadpublic()
: f =
open
('public.txt'
,'r'
)return f.
read
()
rsakey = rsa.
importkey
(loadpublic()
)cipher = cipher_pkcs1_v1_5.
new(rsakey)
# 密碼加密
cipher_text = base64.
b64encode
(cipher.
encrypt((
bytes
('111'
.encode
("utf8"))
)))cipher_text = cipher_text.
decode
('utf-8'
)print
(cipher_text)
加密生成的字串
私匙解密
私匙儲存在伺服器,可以儲存在資料庫,也可以儲存成txt
rsakey = rsa.
importkey
(private_pen)
cipher = cipher_pkcs1_v1_5.
new(rsakey)
text = cipher.
decrypt
(base64.
b64decode
(token)
, none)
text = text.
decode
('utf-8'
)
python RSA 公私鑰 對檔案加密解密
使用rsa模組 import rsa import base64 讀取私鑰 privkey rsa.privatekey.load pkcs1 open private.pem rb read 讀取公鑰 pubkey rsa.publickey.load pkcs1 open public.pem ...
python rsa非對稱加密
使用指令碼生成私鑰和金鑰 from crypto import random from crypto.publickey import rsa random generator random.new read rsa rsa.generate 2048 random generator 生成私鑰 p...
python RSA 公鑰解密方法
常見的rsa加解密使用方式是 公鑰加密,私鑰解密。私鑰簽名,公鑰驗籤。但我在專案上卻遇到了乙個用python解決公鑰解密的問題。查了好多資料最後完成了這需求,記錄一下。import base64 from rsa import core,publickey,transform def public ...