您能帮忙解决以下问题吗?
我是python中新的加密和解密对象。
为我提供了pgp private.key和public.key文件,以便对文本文件进行简单的加密和解密。
import gnupg as g
import os
from datetime import datetime
#Home directory
gpg = g.GPG('/key/')
date1 =datetime.today().strftime('%Y%m%d')
file1_combined_faia_csv='test_file.txt'
file1_combined_faia='test_encry.pgp'
key_data = None
print 'pen the public key file.'
with open('priv.key','rb') as f:
Key_data = f.read()
print 'Importing Key data from the keydata'
key = gpg.import_keys(Key_data)
#List the Keys from the data
pub_key = gpg.list_keys()
key_data = pub_key[2]
with open(file1_combined_faia_csv,'rb') as file:
file_data= file.read()
data = gpg.encrypt(file_data,key_data["keyid"])
with open(file1_combined_faia,'w+') as dec:
dec.write(str(data))
print 'for PIC Encryption done!!!'
print 'OK: ' + str(data.ok)
print 'Msg: ' + str(data.status)
print 'Error: ' + str(data.stderr)
打击是我的原始弦乐。
Hi this is tharun from data team.
它成功加密。 请看下面我的解密代码。客户也向我提供了密码短语。
import gnupg as g
import os
from datetime import datetime
#Home directory
gpg = g.GPG('/key/')
date1 =datetime.today().strftime('%Y%m%d')
file1_combined_faia_csv='test_encry.pgp'
file1_combined_faia='test_decryped.txt'
key_data = None
print 'pen the private key file.'
with open('priv.key','rb') as f:
Key_data = f.read()
key = gpg.import_keys(Key_data)
pub_key = gpg.list_keys(True)
key_data = pub_key[0]
file_data = None
print 'for FAIA Encrypting.........'
with open(file1_combined_faia_csv,'rb') as file:
file_data= file.read()
data = gpg.decrypt(str(file_data),passphrase="*************"
with open(file1_combined_faia,'w+') as dec:
dec.write(str(data))
print 'for PIC Decryption done!!!'
print 'OK: ' + str(data.ok)
print 'Msg: ' + str(data.status)
print 'Error: ' + str(data.stderr)
下面是错误消息
[GNUPG:] NO_SECKEY D43DA661974C8582
[GNUPG:] BEGIN_DECRYPTION
[GNUPG:] DECRYPTION_FAILED
gpg: decryption failed: No secret key
[GNUPG:] END_DECRYPTION
我正在根据一些示例教程来做上述事情。我想我在解密时错过了一些东西。我可能同时使用私钥和密码短语,但不确定如何使用。
您能在解密部分帮助我吗?
请让我知道是否需要更多信息。
谢谢