-1
在我的Linux Debian服務器上,使用python,我試圖逐行讀取文件名並使用公共RSA對其進行加密。然後我想將加密的行與另一個我已經加密的文件進行比較。如果它們彼此相等,我想以解密和加密的形式打印出名稱。我從來沒有使用Python,所以任何幫助將不勝感激。使用RSA在Python中逐行加密文件並將其與其他文件進行比較
#!/usr/bin/python
from Crypto.PublicKey import RSA
key = RSA.generate(2048)
names = open('names.txt')
cipher = open('ciphertext.txt',"r")
readname = names.readline()
readcipher = cipher.readlines()
while readname:
enc_name = pubkey.encrypt(names,0)
if enc_name == readcipher:
print readname
readname = names.readline()
names.close()
cipher.close()
爲什麼你使用RSA,你需要不同的加密和解密密鑰嗎?請注意,您可以加密的數據大小限制爲略小於密鑰大小。數據通常使用對稱密鑰算法(如AES)進行加密。 – zaph