當前位置: 首頁>>代碼示例>>Python>>正文


Python GLBPGP.encrypt_file方法代碼示例

本文整理匯總了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))
開發者ID:RuanAragao,項目名稱:GlobaLeaks,代碼行數:35,代碼來源:test_gpg.py

示例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()
開發者ID:Taipo,項目名稱:GlobaLeaks,代碼行數:28,代碼來源:test_security.py


注:本文中的globaleaks.security.GLBPGP.encrypt_file方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。