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


Java PGPPublicKey.getSignatures方法代码示例

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


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

示例1: verifyPublicKey

import org.bouncycastle.openpgp.PGPPublicKey; //导入方法依赖的package包/类
/**
 * Verifies that a public key is signed with another public key
 *
 * @param keyToVerify the public key to verify
 * @param id the id we are verifying against the public key
 * @param keyToVerifyWith the key to verify with
 *
 * @return true if verified, false otherwise
 */
public static boolean verifyPublicKey( PGPPublicKey keyToVerify, String id, PGPPublicKey keyToVerifyWith )
        throws PGPException
{
    try
    {
        Iterator<PGPSignature> signIterator = keyToVerify.getSignatures();
        while ( signIterator.hasNext() )
        {
            PGPSignature signature = signIterator.next();
            signature.init( new JcaPGPContentVerifierBuilderProvider().setProvider( provider ), keyToVerifyWith );
            if ( signature.verifyCertification( id.getBytes(), keyToVerify ) )
            {
                return true;
            }
        }
        return false;
    }
    catch ( Exception e )
    {
        //throw custom  exception
        throw new PGPException( "Error verifying public key", e );
    }
}
 
开发者ID:subutai-io,项目名称:base,代码行数:33,代码来源:PGPEncryptionUtil.java

示例2: printPublicKeySignatures

import org.bouncycastle.openpgp.PGPPublicKey; //导入方法依赖的package包/类
private boolean printPublicKeySignatures( PGPPublicKey publicKey, final PGPPublicKey secondPublicKey )
{
    boolean verification = false;
    try
    {
        verification = PGPEncryptionUtil
                .verifyPublicKey( publicKey, Long.toHexString( secondPublicKey.getKeyID() ), secondPublicKey );
    }
    catch ( PGPException e )
    {
        e.printStackTrace();
    }
    logger.info( "%%%%%%%%%%%%% Signature verification: " + verification );
    Iterator keySignatures = publicKey.getSignatures();
    while ( keySignatures.hasNext() )
    {
        PGPSignature signature = ( PGPSignature ) keySignatures.next();
        signature.getSignatureType();
        logger.info( Long.toHexString( signature.getKeyID() ) );
    }
    return verification;
}
 
开发者ID:subutai-io,项目名称:base,代码行数:23,代码来源:PGPEncryptionUtilTest.java

示例3: hasOneOfExpectedKeyFlags

import org.bouncycastle.openpgp.PGPPublicKey; //导入方法依赖的package包/类
/**
 * Checks whether one of the signatures of the key has one of the expected
 * key flags
 * 
 * @param key
 * @return {@link Boolean#TRUE} if key has one of the expected flag,
 *         <code>null</code> if the key does not have any key flags,
 *         {@link Boolean#FALSE} if the key has none of the expected flags
 */
private static Boolean hasOneOfExpectedKeyFlags(PGPPublicKey key, int[] expectedKeyFlags) {
    boolean containsKeyFlags = false;
    for (@SuppressWarnings("unchecked")
    Iterator<PGPSignature> itsig = key.getSignatures(); itsig.hasNext();) {
        PGPSignature sig = itsig.next();
        PGPSignatureSubpacketVector subPacks = sig.getHashedSubPackets();
        if (subPacks != null) {
            int keyFlag = subPacks.getKeyFlags();
            if (keyFlag > 0 && !containsKeyFlags) {
                containsKeyFlags = true;
            }
            for (int expectdKeyFlag : expectedKeyFlags) {
                int result = keyFlag & expectdKeyFlag;
                if (result == expectdKeyFlag) {
                    return Boolean.TRUE;
                }
            }
        }
    }
    if (containsKeyFlags) {
        return Boolean.FALSE;
    }
    return null; // no key flag
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:34,代码来源:PGPDataFormatUtil.java

示例4: checkPublicKeyRingWithX509

import org.bouncycastle.openpgp.PGPPublicKey; //导入方法依赖的package包/类
private void checkPublicKeyRingWithX509(byte[] keyRing)
    throws Exception
{
    PGPPublicKeyRing pubRing = new PGPPublicKeyRing(keyRing, new BcKeyFingerprintCalculator());
    Iterator         it = pubRing.getPublicKeys();

    if (it.hasNext())
    {
        PGPPublicKey key = (PGPPublicKey)it.next();

        Iterator sIt = key.getSignatures();

        if (sIt.hasNext())
        {
            PGPSignature sig = (PGPSignature)sIt.next();
            if (sig.getKeyAlgorithm() != 100)
            {
                fail("experimental signature not found");
            }
            if (!areEqual(sig.getSignature(), Hex.decode("000101")))
            {
                fail("experimental encoding check failed");
            }
        }
        else
        {
            fail("no signature found");
        }
    }
    else
    {
        fail("no key found");
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:35,代码来源:BcPGPKeyRingTest.java

示例5: removeSignature

import org.bouncycastle.openpgp.PGPPublicKey; //导入方法依赖的package包/类
public static PGPPublicKeyRing removeSignature( PGPPublicKeyRing keyToRemoveFrom,
                                                PGPPublicKey keySignatureToRemove ) throws PGPException
{
    try
    {
        PGPPublicKey oldKey = keyToRemoveFrom.getPublicKey();

        PGPPublicKeyRing newPublicKeyRing = PGPPublicKeyRing.removePublicKey( keyToRemoveFrom, oldKey );

        Iterator<PGPSignature> signIterator = oldKey.getSignatures();
        while ( signIterator.hasNext() )
        {
            PGPSignature signature = signIterator.next();
            signature.init( new JcaPGPContentVerifierBuilderProvider().setProvider( provider ),
                    keySignatureToRemove );

            String sigId = PGPKeyUtil.encodeNumericKeyId( oldKey.getKeyID() );

            if ( signature.verifyCertification( sigId, oldKey ) )
            {
                PGPPublicKey updatedKey = PGPPublicKey.removeCertification( oldKey, signature );
                keyToRemoveFrom = PGPPublicKeyRing.insertPublicKey( newPublicKeyRing, updatedKey );
            }
        }

        return keyToRemoveFrom;
    }
    catch ( Exception e )
    {
        //throw custom  exception
        throw new PGPException( "Error removing signature", e );
    }
}
 
开发者ID:subutai-io,项目名称:base,代码行数:34,代码来源:PGPEncryptionUtil.java

示例6: getSignatures

import org.bouncycastle.openpgp.PGPPublicKey; //导入方法依赖的package包/类
/**
 * Returns a map containing key IDs and corresponding signatures.
 */
public static Map<Long, PGPSignature> getSignatures( PGPPublicKey pubKey )
{
    HashMap<Long, PGPSignature> sigs = new HashMap<>();
    Iterator signatures = pubKey.getSignatures();

    while ( signatures.hasNext() )
    {
        PGPSignature sign = ( PGPSignature ) signatures.next();

        sigs.put( sign.getKeyID(), sign );
    }

    return sigs;
}
 
开发者ID:subutai-io,项目名称:base,代码行数:18,代码来源:PGPSignatureUtil.java

示例7: generateTest

import org.bouncycastle.openpgp.PGPPublicKey; //导入方法依赖的package包/类
public void generateTest()
    throws Exception
{
    char[]              passPhrase = "hello".toCharArray();
    DSAParametersGenerator  dsaPGen = new DSAParametersGenerator();

    dsaPGen.init(512, 10, new SecureRandom());

    DSAKeyPairGenerator    dsaKpg = new DSAKeyPairGenerator();

    dsaKpg.init(new DSAKeyGenerationParameters(new SecureRandom(), dsaPGen.generateParameters()));

    //
    // this takes a while as the key generator has to generate some DSA params
    // before it generates the key.
    //
    AsymmetricCipherKeyPair  dsaKp = dsaKpg.generateKeyPair();

    ElGamalKeyPairGenerator elgKpg = new ElGamalKeyPairGenerator();
    BigInteger             g = new BigInteger("153d5d6172adb43045b68ae8e1de1070b6137005686d29d3d73a7749199681ee5b212c9b96bfdcfa5b20cd5e3fd2044895d609cf9b410b7a0f12ca1cb9a428cc", 16);
    BigInteger             p = new BigInteger("9494fec095f3b85ee286542b3836fc81a5dd0a0349b4c239dd38744d488cf8e31db8bcb7d33b41abb9e5a33cca9144b1cef332c94bf0573bf047a3aca98cdf3b", 16);
    
    ElGamalParameters         elParams = new ElGamalParameters(p, g);
    
    elgKpg.init(new ElGamalKeyGenerationParameters(new SecureRandom(), elParams));

    //
    // this is quicker because we are using pregenerated parameters.
    //
    AsymmetricCipherKeyPair           elgKp = elgKpg.generateKeyPair();
    PGPKeyPair        dsaKeyPair = new BcPGPKeyPair(PGPPublicKey.DSA, dsaKp, new Date());
    PGPKeyPair        elgKeyPair = new BcPGPKeyPair(PGPPublicKey.ELGAMAL_ENCRYPT, elgKp, new Date());

    PGPKeyRingGenerator    keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, dsaKeyPair,
            "test", null, null, null, new BcPGPContentSignerBuilder(PGPPublicKey.DSA, HashAlgorithmTags.SHA1), new BcPBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256).build(passPhrase));

    keyRingGen.addSubKey(elgKeyPair);

    PGPSecretKeyRing       keyRing = keyRingGen.generateSecretKeyRing();
    
    keyRing.getSecretKey().extractPrivateKey(new BcPBESecretKeyDecryptorBuilder(new BcPGPDigestCalculatorProvider()).build(passPhrase));
    
    PGPPublicKeyRing        pubRing = keyRingGen.generatePublicKeyRing();
    
    PGPPublicKey            vKey = null;
    PGPPublicKey            sKey = null;
    
    Iterator                    it = pubRing.getPublicKeys();
    while (it.hasNext())
    {
        PGPPublicKey    pk = (PGPPublicKey)it.next();
        if (pk.isMasterKey())
        {
            vKey = pk;
        }
        else
        {
            sKey = pk;
        }
    }
    
    Iterator    sIt = sKey.getSignatures();
    while (sIt.hasNext())
    {
        PGPSignature    sig = (PGPSignature)sIt.next();
        
        if (sig.getKeyID() == vKey.getKeyID()
            && sig.getSignatureType() == PGPSignature.SUBKEY_BINDING)
        {
            sig.init(new BcPGPContentVerifierBuilderProvider(), vKey);

            if (!sig.verifyCertification(vKey, sKey))
            {
                fail("failed to verify sub-key signature.");
            }
        }
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:79,代码来源:BcPGPKeyRingTest.java

示例8: generateSha1Test

import org.bouncycastle.openpgp.PGPPublicKey; //导入方法依赖的package包/类
public void generateSha1Test()
    throws Exception
{
    char[]              passPhrase = "hello".toCharArray();
    DSAParametersGenerator  dsaPGen = new DSAParametersGenerator();

    dsaPGen.init(512, 10, new SecureRandom());

    DSAKeyPairGenerator    dsaKpg = new DSAKeyPairGenerator();

    dsaKpg.init(new DSAKeyGenerationParameters(new SecureRandom(), dsaPGen.generateParameters()));

    //
    // this takes a while as the key generator has to generate some DSA params
    // before it generates the key.
    //
    AsymmetricCipherKeyPair dsaKp = dsaKpg.generateKeyPair();

    ElGamalKeyPairGenerator    elgKpg = new ElGamalKeyPairGenerator();
    BigInteger             g = new BigInteger("153d5d6172adb43045b68ae8e1de1070b6137005686d29d3d73a7749199681ee5b212c9b96bfdcfa5b20cd5e3fd2044895d609cf9b410b7a0f12ca1cb9a428cc", 16);
    BigInteger             p = new BigInteger("9494fec095f3b85ee286542b3836fc81a5dd0a0349b4c239dd38744d488cf8e31db8bcb7d33b41abb9e5a33cca9144b1cef332c94bf0573bf047a3aca98cdf3b", 16);
    
    ElGamalParameters         elParams = new ElGamalParameters(p, g);
    
    elgKpg.init(new ElGamalKeyGenerationParameters(new SecureRandom(), elParams));

    //
    // this is quicker because we are using pregenerated parameters.
    //
    AsymmetricCipherKeyPair                   elgKp = elgKpg.generateKeyPair();
    PGPKeyPair        dsaKeyPair = new BcPGPKeyPair(PGPPublicKey.DSA, dsaKp, new Date());
    PGPKeyPair        elgKeyPair = new BcPGPKeyPair(PGPPublicKey.ELGAMAL_ENCRYPT, elgKp, new Date());
    PGPDigestCalculator chkSumCalc = new BcPGPDigestCalculatorProvider().get(HashAlgorithmTags.SHA1);

    PGPKeyRingGenerator    keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, dsaKeyPair,
            "test", chkSumCalc, null, null, new BcPGPContentSignerBuilder(PGPPublicKey.DSA, HashAlgorithmTags.SHA1), new BcPBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256).build(passPhrase));
    keyRingGen.addSubKey(elgKeyPair);

    PGPSecretKeyRing       keyRing = keyRingGen.generateSecretKeyRing();
    
    keyRing.getSecretKey().extractPrivateKey(new BcPBESecretKeyDecryptorBuilder(new BcPGPDigestCalculatorProvider()).build(passPhrase));
    
    PGPPublicKeyRing        pubRing = keyRingGen.generatePublicKeyRing();
    
    PGPPublicKey            vKey = null;
    PGPPublicKey            sKey = null;
    
    Iterator                    it = pubRing.getPublicKeys();
    while (it.hasNext())
    {
        PGPPublicKey    pk = (PGPPublicKey)it.next();
        if (pk.isMasterKey())
        {
            vKey = pk;
        }
        else
        {
            sKey = pk;
        }
    }
    
    Iterator    sIt = sKey.getSignatures();
    while (sIt.hasNext())
    {
        PGPSignature    sig = (PGPSignature)sIt.next();
        
        if (sig.getKeyID() == vKey.getKeyID()
            && sig.getSignatureType() == PGPSignature.SUBKEY_BINDING)
        {
            sig.init(new BcPGPContentVerifierBuilderProvider(), vKey);

            if (!sig.verifyCertification(vKey, sKey))
            {
                fail("failed to verify sub-key signature.");
            }
        }
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:79,代码来源:BcPGPKeyRingTest.java


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