本文整理汇总了Python中gnupg.GPG.decrypt方法的典型用法代码示例。如果您正苦于以下问题:Python GPG.decrypt方法的具体用法?Python GPG.decrypt怎么用?Python GPG.decrypt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gnupg.GPG
的用法示例。
在下文中一共展示了GPG.decrypt方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_job_unit
# 需要导入模块: from gnupg import GPG [as 别名]
# 或者: from gnupg.GPG import decrypt [as 别名]
def do_job_unit(self, event, corpus, unit, **kwargs):
preroll = kwargs.get("preroll", 0)
for i, (domain, count, path, url) in enumerate(self.get_chunk_info_paths_urls(
event, corpus, preroll=preroll)):
if i != unit:
continue
gpg = GPG()
#http = urllib3.PoolManager()
parent = os.path.dirname(path)
if not os.path.exists(parent):
try:
os.makedirs(parent)
except OSError as e:
if e.errno == errno.EEXIST and os.path.isdir(parent):
pass
retries = 3
while 1:
try:
r = requests.get(url, timeout=30)
with open(path, u'wb') as f:
f.write(str(gpg.decrypt(r.content)))
break
except requests.exceptions.ConnectionError:
retries -= 1
if retries == 0:
break
except urllib3.exceptions.ReadTimeoutError:
retries -= 1
if retries == 0:
break
示例2: extract_content
# 需要导入模块: from gnupg import GPG [as 别名]
# 或者: from gnupg.GPG import decrypt [as 别名]
def extract_content(path, keyring, output_dir, output_ext):
""" Use the keyring to decrypt a document """
name = os.path.splitext(os.path.basename(path))[0]
gpg = GPG(gnupghome=keyring)
new_path = os.path.join(output_dir, '.'.join([name, output_ext]))
try:
with open(path, 'rb') as content:
data = gpg.decrypt(content.read(), output=new_path)
except OSError:
raise DecryptionError("Could not open '%s'" % path, path)
return new_path
示例3: scchunk_worker_
# 需要导入模块: from gnupg import GPG [as 别名]
# 或者: from gnupg.GPG import decrypt [as 别名]
def scchunk_worker_(job_queue, result_queue, **kwargs):
signal.signal(signal.SIGINT, signal.SIG_IGN)
gpg = GPG()
http = urllib3.PoolManager(timeout=15.0, retries=3)
while not job_queue.empty():
try:
path, url = job_queue.get(block=False)
parent = os.path.dirname(path)
if not os.path.exists(parent):
try:
os.makedirs(parent)
except OSError as e:
if e.errno == errno.EEXIST and os.path.isdir(parent):
pass
r = http.request('GET', url)
with open(path, u'wb') as f:
f.write(str(gpg.decrypt(r.data)))
result_queue.put(None)
except Queue.Empty:
pass
示例4: __init__
# 需要导入模块: from gnupg import GPG [as 别名]
# 或者: from gnupg.GPG import decrypt [as 别名]
#.........这里部分代码省略.........
rowtime = timestamp - self.storeTime
cur.execute('DELETE FROM skipped_mk WHERE timestamp < ?',
(rowtime,))
def trySkippedMK(self, msg, pad_length, name, other_name):
with self.db:
cur = self.db.cursor()
cur.execute('SELECT * FROM skipped_mk')
rows = cur.fetchall()
for row in rows:
if name == row[0] and other_name == row[1]:
msg1 = msg[:106 - pad_length]
msg2 = msg[106:]
header = self.dec(a2b_base64(row[2]), msg1)
body = self.dec(a2b_base64(row[3]), msg2)
if header != '' and body != '':
cur.execute('DELETE FROM skipped_mk WHERE mk = ?',
(row[3],))
return body
return False
def stageSkippedMK(self, HKr, Nr, Np, CKr):
CKp = CKr
for i in range(Np - Nr):
mk = sha256(CKp + '0').digest()
CKp = sha256(CKp + '1').digest()
self.staged_HK_mk[mk] = HKr
mk = sha256(CKp + '0').digest()
CKp = sha256(CKp + '1').digest()
return CKp, mk
def decrypt(self, msg):
pad = msg[105:106]
pad_length = ord(pad)
msg1 = msg[:106 - pad_length]
body = self.trySkippedMK(msg, pad_length, self.state['name'],
self.state['other_name'])
if body and body != '':
return body
header = None
if self.state['HKr']:
header = self.dec(self.state['HKr'], msg1)
if header and header != '':
Np = int(header[:3])
CKp, mk = self.stageSkippedMK(self.state['HKr'], self.state['Nr'],
Np, self.state['CKr'])
body = self.dec(mk, msg[106:])
if not body or body == '':
raise (Axolotl_exception('Undecipherable message'))
else:
header = self.dec(self.state['NHKr'], msg1)
if self.state['ratchet_flag'] or not header or header == '':
raise (Axolotl_exception('Undecipherable message'))
Np = int(header[:3])
PNp = int(header[3:6])
DHRp = header[6:]
if self.state['CKr']:
self.stageSkippedMK(self.state['HKr'], self.state['Nr'], PNp,
self.state['CKr'])
HKp = self.state['NHKr']
RKp = sha256(
示例5: GPG
# 需要导入模块: from gnupg import GPG [as 别名]
# 或者: from gnupg.GPG import decrypt [as 别名]
#!/usr/bin/env python
import requests
from gnupg import GPG
passphrase = None
if __name__ == "__main__":
gpg = GPG()
url = "http://127.0.0.1:8000/students/crypto/"
r = requests.get(url)
print "cifrado", r.text
content = gpg.decrypt(r.text, always_trust=True, passphrase=passphrase)
print "decifrado"
if not content:
print "No se pudo descifrar"
else:
print content
示例6: GPG
# 需要导入模块: from gnupg import GPG [as 别名]
# 或者: from gnupg.GPG import decrypt [as 别名]
gpg = GPG(binary='/usr/bin/gpg2',
homedir='~/.gnupg',
keyring='pubring.gpg',
secring='secring.gpg')
stored_keys = gpg.list_keys()
message = "This is a test message to be encripted."
options_enc = {
'passphrase': passphrase,
'armor': True,
'default_key': gpg_test_fingerprint
}
encrypted_msg = gpg.encrypt(message, gpg_test_fingerprint, **options_enc)
print(encrypted_msg)
options_dec = {
'passphrase': passphrase
}
decrypted_msg = gpg.decrypt(str(encrypted_msg), **options_dec)
assert message == str(decrypted_msg)
print("This is the original message:", decrypted_msg)
''' "Valid" will return a boolean saying whether the decrypted message's
signature is valid.'''
assert decrypted_msg.valid
示例7: dec
# 需要导入模块: from gnupg import GPG [as 别名]
# 或者: from gnupg.GPG import decrypt [as 别名]
def dec(data, key):
gpg = GPG()
return gpg.decrypt()
示例8: deciphersteg
# 需要导入模块: from gnupg import GPG [as 别名]
# 或者: from gnupg.GPG import decrypt [as 别名]
def deciphersteg(stegdata, cipher, key, aesmode, verbose=False, unprep=True):
# Decipher hidden message from array of data hidden in JT65 errors
stegedmsg = ""
stegedmsgba = np.array(range(0), dtype=np.int32)
statusar = []
for index, value in enumerate(stegdata):
if unprep:
value = jt.unprepsteg(value) # Decode real data from FEC
if cipher == "none":
recoveredtext = jt.decode(value)[0:13]
if verbose:
print "Steg Text in Message " + str(index) + " : " + recoveredtext
stegedmsg += recoveredtext
elif cipher == "XOR" or cipher == "OTP":
thesebytes = jt65tobytes(value)
thisstatus = thesebytes[0:1]
if thisstatus & 0x40 == 0x40:
# This is the last packet, signals how many bytes to read
bytestoread = thisstatus & 0x3F
thisunstegbytes = thesebytes[1:bytestoread + 1]
else:
thisunstegbytes = thesebytes[1:]
if verbose:
print "Steg Data in Message " + str(index) + " : " + str(thisunstegbytes)
stegedmsgba = np.append(stegedmsgba, thisunstegbytes)
else:
thesebytes = jt65tobytes(value)
thisunstegbytes = thesebytes[1:10]
if verbose:
print "Steg Data in Message " + str(index) + " : " + str(thisunstegbytes)
stegedmsgba = np.append(stegedmsgba, thisunstegbytes)
if cipher == "XOR":
if verbose:
print"Cipher Data : " + str(stegedmsgba)
finalcipherdata = (
''.join('{0:02x}'.format(int(e)).decode("hex") for e in stegedmsgba))
if verbose:
print"Cipher Data Hex : " + finalcipherdata
cryptobj = XOR.new(key)
stegedmsg = cryptobj.decrypt(finalcipherdata)
if cipher == "ARC4":
if verbose:
print"Cipher Data : " + str(stegedmsgba)
finalcipherdata = (
''.join('{0:02x}'.format(int(e)).decode("hex") for e in stegedmsgba))
if verbose:
print"Cipher Data Hex : " + finalcipherdata
tempkey = SHA.new(key).digest()
cryptobj = ARC4.new(tempkey)
stegedmsg = cryptobj.decrypt(finalcipherdata)
if cipher == "AES":
if verbose:
print"Cipher Data : " + str(stegedmsgba)
finalcipherdata = (
''.join('{0:02x}'.format(int(e)).decode("hex") for e in stegedmsgba))
if verbose:
print"Cipher Data Hex : " + finalcipherdata
if aesmode == "ECB":
cryptobj = AES.new(key, AES.MODE_ECB)
elif aesmode == "CBC":
cryptobj = AES.new(key, AES.MODE_CBC, finalcipherdata[0:16])
finalcipherdata = finalcipherdata[16:]
elif aesmode == "CFB":
cryptobj = AES.new(key, AES.MODE_CFB, finalcipherdata[0:16])
finalcipherdata = finalcipherdata[16:]
stegedmsg = cryptobj.decrypt(finalcipherdata)
if cipher == "GPG":
if verbose:
print"Cipher Data : " + str(stegedmsgba)
finalcipherdata = (
''.join('{0:02x}'.format(int(e)).decode("hex") for e in stegedmsgba))
if verbose:
print"Cipher Data Hex : " + finalcipherdata
gpg = GPG()
stegedmsg = gpg.decrypt(finalcipherdata)
#.........这里部分代码省略.........