本文整理汇总了Python中globaleaks.security.GLBPGP.encrypt_file方法的典型用法代码示例。如果您正苦于以下问题:Python GLBPGP.encrypt_file方法的具体用法?Python GLBPGP.encrypt_file怎么用?Python GLBPGP.encrypt_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类globaleaks.security.GLBPGP
的用法示例。
在下文中一共展示了GLBPGP.encrypt_file方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_encrypt_file
# 需要导入模块: from globaleaks.security import GLBPGP [as 别名]
# 或者: from globaleaks.security.GLBPGP import encrypt_file [as 别名]
def test_encrypt_file(self):
# setup the PGP key before
GLSetting.pgproot = PGPROOT
tempsource = os.path.join(os.getcwd(), "temp_source.txt")
with file(tempsource, 'w+') as f1:
f1.write("\n\nDecrypt the Cat!\n\nhttp://tobtu.com/decryptocat.php\n\n")
f1.seek(0)
fake_receiver_desc = {
'pgp_key_public': unicode(VALID_PGP_KEY1),
'pgp_key_status': u'enabled',
'pgp_key_fingerprint': u"CF4A22020873A76D1DCB68D32B25551568E49345",
'username': u'[email protected]',
}
# these are the same lines used in delivery_sched.py
pgpobj = GLBPGP()
pgpobj.load_key(VALID_PGP_KEY1)
encrypted_file_path, encrypted_file_size = pgpobj.encrypt_file(fake_receiver_desc['pgp_key_fingerprint'],
tempsource, f1, "/tmp")
pgpobj.destroy_environment()
with file(encrypted_file_path, "r") as f2:
first_line = f2.readline()
self.assertSubstring('-----BEGIN PGP MESSAGE-----', first_line)
with file(encrypted_file_path, "r") as f2:
whole = f2.read()
self.assertEqual(encrypted_file_size, len(whole))
示例2: test_encrypt_file
# 需要导入模块: from globaleaks.security import GLBPGP [as 别名]
# 或者: from globaleaks.security.GLBPGP import encrypt_file [as 别名]
def test_encrypt_file(self):
file_src = os.path.join(os.getcwd(), 'test_plaintext_file.txt')
file_dst = os.path.join(os.getcwd(), 'test_encrypted_file.txt')
fake_receiver_desc = {
'pgp_key_public': helpers.PGPKEYS['VALID_PGP_KEY1_PRV'],
'pgp_key_fingerprint': u'ECAF2235E78E71CD95365843C7B190543CAA7585',
'username': u'[email protected]',
}
# these are the same lines used in delivery_sched.py
pgpobj = GLBPGP()
pgpobj.load_key(helpers.PGPKEYS['VALID_PGP_KEY1_PRV'])
with open(file_src, 'w+') as f:
f.write(self.secret_content)
f.seek(0)
encrypted_object, length = pgpobj.encrypt_file(fake_receiver_desc['pgp_key_fingerprint'],
f,
file_dst)
with open(file_dst, 'r') as f:
self.assertEqual(str(pgpobj.gnupg.decrypt_file(f)), self.secret_content)
pgpobj.destroy_environment()