2016-03-08 74 views
-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() 
+2

爲什麼你使用RSA,你需要不同的加密和解密密鑰嗎?請注意,您可以加密的數據大小限制爲略小於密鑰大小。數據通常使用對稱密鑰算法(如AES)進行加密。 – zaph

回答

0

我不知道你的實際問題是什麼,但也許這會有所幫助?

for name_plaintext,name_encoded in zip(names,cipher): 
    if do_encode(name_plaintext) == name_encoded: 
     print name_decoded,"==>",name_encoded 
+0

http://blog.ircmaxell.com/2014/11/its-all-about-time.html –

相關問題