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


Java PGPSecretKeyRingCollection.getSecretKeyRing方法代码示例

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


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

示例1: test_key

import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; //导入方法依赖的package包/类
public void test_key(BigInteger keyId, String passphrase)
    throws Exception
{

    PGPSecretKeyRingCollection secretKeyRing = loadSecretKeyCollection("secring.gpg");

    PGPSecretKeyRing secretKey = secretKeyRing.getSecretKeyRing(keyId.longValue());
    assertNotNull("Could not locate secret keyring with Id=" + keyId.toString(16), secretKey);

    PGPSecretKey key = secretKey.getSecretKey();
    assertNotNull("Could not locate secret key!", key);

    try
    {
        PGPDigestCalculatorProvider calcProvider = new JcaPGPDigestCalculatorProviderBuilder()
            .setProvider(BouncyCastleProvider.PROVIDER_NAME).build();

        PBESecretKeyDecryptor decryptor = new JcePBESecretKeyDecryptorBuilder(calcProvider)
            .setProvider(BouncyCastleProvider.PROVIDER_NAME).build(passphrase.toCharArray());

        PGPPrivateKey privateKey = key.extractPrivateKey(decryptor);

        assertTrue(privateKey.getKeyID() == keyId.longValue());

    }
    catch (PGPException e)
    {
        throw new PGPException("Password incorrect!", e);
    }

    // all fine!
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:33,代码来源:PGPUnicodeTest.java

示例2: testMessageSigning

import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; //导入方法依赖的package包/类
@Test
public void testMessageSigning() throws Exception
{
    InputStream secondSecretStream = findFile( PLUGIN_PRIVATE_KEY );
    InputStream secondPublicStream = findFile( PLUGIN_PUBLIC_KEY );

    PGPSecretKeyRingCollection secretKeyRingCollection =
            new PGPSecretKeyRingCollection( PGPUtil.getDecoderStream( secondSecretStream ),
                    new JcaKeyFingerprintCalculator() );

    PGPSecretKeyRing secretKeyRing = secretKeyRingCollection
            .getSecretKeyRing( secretKeyRingCollection.iterator().next().getSecretKey().getKeyID() );

    PGPSecretKey secondSecretKey = secretKeyRing.getSecretKey();

    PGPPublicKeyRingCollection secondPublicKeyRingCollection =
            new PGPPublicKeyRingCollection( PGPUtil.getDecoderStream( secondPublicStream ),
                    new JcaKeyFingerprintCalculator() );


    PGPPublicKeyRing pgpKeyring = secondPublicKeyRingCollection
            .getPublicKeyRing( secondPublicKeyRingCollection.iterator().next().getPublicKey().getKeyID() );


    byte[] encryptedMessage =
            PGPEncryptionUtil.encrypt( "Test message.\n".getBytes(), pgpKeyring.getPublicKey(), true );

    byte[] signedMessageArmor =
            PGPEncryptionUtil.clearSign( encryptedMessage, secondSecretKey, "123".toCharArray(), "" );

    String signedMessage = new String( signedMessageArmor, "UTF-8" );

    logger.info( "\n" + signedMessage );
    logger.info( "\n======================" );

    boolean result = PGPEncryptionUtil.verifyClearSign( signedMessageArmor, pgpKeyring );
    if ( result )
    {
        logger.info( "signature verified." );
    }
    else
    {
        logger.info( "signature verification failed." );
    }

    byte[] extracted = PGPEncryptionUtil.extractContentFromClearSign( signedMessage.getBytes() );
    byte[] decrypted = PGPEncryptionUtil.decrypt( extracted, secretKeyRing, "123" );
    logger.info( "Decrypted message \n" + new String( decrypted, "UTF-8" ) );

    assertEquals( true, result );
}
 
开发者ID:subutai-io,项目名称:base,代码行数:52,代码来源:PGPEncryptionUtilTest.java

示例3: testClearSign

import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; //导入方法依赖的package包/类
@Test
public void testClearSign() throws Exception
{
    InputStream secondSecretStream = findFile( PLUGIN_PRIVATE_KEY );
    InputStream secondPublicStream = findFile( PLUGIN_PUBLIC_KEY );

    PGPSecretKeyRingCollection secretKeyRingCollection =
            new PGPSecretKeyRingCollection( PGPUtil.getDecoderStream( secondSecretStream ),
                    new JcaKeyFingerprintCalculator() );

    PGPSecretKeyRing secretKeyRing = secretKeyRingCollection
            .getSecretKeyRing( secretKeyRingCollection.iterator().next().getPublicKey().getKeyID() );

    PGPSecretKey secondSecretKey = secretKeyRing.getSecretKey();

    PGPPublicKeyRingCollection secondPublicKeyRingCollection =
            new PGPPublicKeyRingCollection( PGPUtil.getDecoderStream( secondPublicStream ),
                    new JcaKeyFingerprintCalculator() );


    PGPPublicKeyRing pgpKeyring = secondPublicKeyRingCollection
            .getPublicKeyRing( secondPublicKeyRingCollection.iterator().next().getPublicKey().getKeyID() );

    byte[] signedMessageArmor = PGPEncryptionUtil
            .clearSign( IOUtils.toString( findFile( "message.txt" ) ).getBytes(), secondSecretKey,
                    "123".toCharArray(), "" );

    String signedMessage = new String( signedMessageArmor, "UTF-8" );

    logger.info( "\n" + signedMessage );

    boolean result = PGPEncryptionUtil.verifyClearSign( signedMessage.getBytes(), pgpKeyring );
    if ( result )
    {
        logger.info( "signature verified." );
    }
    else
    {
        logger.info( "signature verification failed." );
    }

    assertEquals( true, result );
}
 
开发者ID:subutai-io,项目名称:base,代码行数:44,代码来源:PGPEncryptionUtilTest.java


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