本文整理汇总了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!
}
示例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 );
}
示例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 );
}