当前位置: 首页>>代码示例>>Python>>正文


Python PGPKey.from_file方法代码示例

本文整理汇总了Python中pgpy.PGPKey.from_file方法的典型用法代码示例。如果您正苦于以下问题:Python PGPKey.from_file方法的具体用法?Python PGPKey.from_file怎么用?Python PGPKey.from_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pgpy.PGPKey的用法示例。


在下文中一共展示了PGPKey.from_file方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_save

# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import from_file [as 别名]
    def test_save(self, kf):
        # load the key and export it back to binary
        key, _ = PGPKey.from_file(kf)
        pgpyblob = key.__bytes__()

        # try loading the exported key
        reloaded, _ = PGPKey.from_file(kf)

        assert pgpyblob == reloaded.__bytes__()
开发者ID:SecurityInnovation,项目名称:PGPy,代码行数:11,代码来源:test_04_PGP_objects.py

示例2: test_sign_encrypted_message

# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import from_file [as 别名]
    def test_sign_encrypted_message(self, sf, cipher):
        # test decrypting a message
        sec, _ = PGPKey.from_file(sf)
        if (sec.fingerprint, cipher) not in self.msgs:
            pytest.skip('Message not present; see test_encrypt_message skip or xfail reason')

        emsg = self.msgs[(sec.fingerprint, cipher)]
        emsg |= sec.sign(emsg)

        assert emsg.is_signed
        assert emsg.is_encrypted
        assert isinstance(next(iter(emsg)), PGPSignature)
开发者ID:SecurityInnovation,项目名称:PGPy,代码行数:14,代码来源:test_05_actions.py

示例3: test_decrypt_message

# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import from_file [as 别名]
    def test_decrypt_message(self, sf, cipher):
        # test decrypting a message
        sec, _ = PGPKey.from_file(sf)
        if (sec.fingerprint, cipher) not in self.msgs:
            pytest.skip('Message not present; see test_encrypt_message skip or xfail reason')

        emsg = self.msgs[(sec.fingerprint, cipher)]
        dmsg = sec.decrypt(emsg)

        assert dmsg.message == "This message will have been encrypted"

        # now check with GnuPG, if possible
        if gpg_ver < '2.1' and sec.key_algorithm in {PubKeyAlgorithm.ECDSA, PubKeyAlgorithm.ECDH}:
            # GnuPG prior to 2.1.x does not support EC* keys, so skip this step
            return

        assert self.gpg_decrypt(emsg, sec).decode('utf-8') == dmsg.message
开发者ID:SecurityInnovation,项目名称:PGPy,代码行数:19,代码来源:test_05_actions.py

示例4: targette_sec

# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import from_file [as 别名]
def targette_sec():
    return PGPKey.from_file('tests/testdata/keys/targette.sec.rsa.asc')[0]
开发者ID:SecurityInnovation,项目名称:PGPy,代码行数:4,代码来源:test_05_actions.py

示例5: targette_pub

# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import from_file [as 别名]
def targette_pub():
    return PGPKey.from_file('tests/testdata/keys/targette.pub.rsa.asc')[0]
开发者ID:SecurityInnovation,项目名称:PGPy,代码行数:4,代码来源:test_05_actions.py

示例6: rsa_pub

# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import from_file [as 别名]
def rsa_pub():
    return PGPKey.from_file('tests/testdata/keys/rsa.1.pub.asc')[0]
开发者ID:escapewindow,项目名称:PGPy,代码行数:4,代码来源:test_10_exceptions.py

示例7: test_load_from_file

# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import from_file [as 别名]
    def test_load_from_file(self, kf):
        key, _ = PGPKey.from_file(kf)

        assert key.fingerprint == _fingerprints[os.path.basename(kf)]
开发者ID:SecurityInnovation,项目名称:PGPy,代码行数:6,代码来源:test_04_PGP_objects.py

示例8: rsa_enc

# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import from_file [as 别名]
def rsa_enc():
    return PGPKey.from_file('tests/testdata/keys/rsa.1.enc.asc')[0]
开发者ID:escapewindow,项目名称:PGPy,代码行数:4,代码来源:test_10_exceptions.py

示例9: test_verify_wrongkey

# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import from_file [as 别名]
    def test_verify_wrongkey(self, rsa_pub):
        wrongkey, _ = PGPKey.from_file('tests/testdata/signatures/aptapproval-test.key.asc')
        sig = PGPSignature.from_file('tests/testdata/signatures/debian-sid.sig.asc')

        with pytest.raises(PGPError):
            wrongkey.verify(_read('tests/testdata/signatures/debian-sid.subj'), sig)
开发者ID:escapewindow,项目名称:PGPy,代码行数:8,代码来源:test_10_exceptions.py

示例10: key

# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import from_file [as 别名]
def key(fn):
    key, _ = PGPKey.from_file(fn)
    return key
开发者ID:SecurityInnovation,项目名称:PGPy,代码行数:5,代码来源:test_04_copy.py

示例11: rtime

# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import from_file [as 别名]
    s2k.count = pgpy.constants.HashAlgorithm.SHA256.tuned_count

    start = rtime()
    sk = s2k.derive_key('sooper_sekret_passphrase')
    elapsed = rtime() - start

    # check that we're actually close to our target
    assert len(sk) == 32
    try:
        assert 0.1 <= round(elapsed, 1) <= 0.2

    except AssertionError:
        warnings.warn("tuned_count: {}; elapsed time: {:.5f}".format(pgpy.constants.HashAlgorithm.SHA256.tuned_count, elapsed))


_seckeys = {sk.key_algorithm.name: sk for sk in (PGPKey.from_file(f)[0] for f in sorted(glob.glob('tests/testdata/keys/*.sec.asc')))}
seckm = [
    _seckeys['DSA']._key,                                # DSA private key packet
    _seckeys['DSA'].subkeys['1FD6D5D4DA0170C4']._key,    # ElGamal private key packet
    _seckeys['RSAEncryptOrSign']._key,                   # RSA private key packet
    _seckeys['ECDSA']._key,                              # ECDSA private key packet
    _seckeys['ECDSA'].subkeys['A81B93FD16BD9806']._key,  # ECDH private key packet
]


@pytest.mark.regression(issue=172)
@pytest.mark.parametrize('keypkt', seckm, ids=[sk.pkalg.name for sk in seckm])
def test_check_checksum(keypkt):
    # this test is dirty and simple
    # take the key packet provided, and store the key material checksum
    # recompute the checksum, and ensure they match
开发者ID:escapewindow,项目名称:PGPy,代码行数:33,代码来源:test_99_regressions.py

示例12: test_load_from_file

# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import from_file [as 别名]
    def test_load_from_file(self, gpg_keyid_file):
        key, _ = PGPKey.from_file(self.kf)

        assert key.fingerprint.keyid in gpg_keyid_file(self.kf.replace('tests/testdata/', ''))
开发者ID:ddddavidee,项目名称:PGPy,代码行数:6,代码来源:test_04_PGP_objects.py


注:本文中的pgpy.PGPKey.from_file方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。