本文整理汇总了Java中org.bouncycastle.openpgp.bc.BcPGPSecretKeyRingCollection类的典型用法代码示例。如果您正苦于以下问题:Java BcPGPSecretKeyRingCollection类的具体用法?Java BcPGPSecretKeyRingCollection怎么用?Java BcPGPSecretKeyRingCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BcPGPSecretKeyRingCollection类属于org.bouncycastle.openpgp.bc包,在下文中一共展示了BcPGPSecretKeyRingCollection类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: provideKeyring
import org.bouncycastle.openpgp.bc.BcPGPSecretKeyRingCollection; //导入依赖的package包/类
/** Always returns a {@link InMemoryKeyring} instance. */
@Provides
static Keyring provideKeyring() {
PGPKeyPair dummyKey;
try (InputStream publicInput = PGP_PUBLIC_KEYRING.openStream();
InputStream privateInput = PGP_PRIVATE_KEYRING.openStream()) {
PGPPublicKeyRingCollection publicKeys =
new BcPGPPublicKeyRingCollection(PGPUtil.getDecoderStream(publicInput));
PGPSecretKeyRingCollection privateKeys =
new BcPGPSecretKeyRingCollection(PGPUtil.getDecoderStream(privateInput));
dummyKey = lookupKeyPair(publicKeys, privateKeys, EMAIL_ADDRESS, ENCRYPT_SIGN);
} catch (PGPException | IOException e) {
throw new VerifyException("Failed to load PGP keys from jar", e);
}
// Use the same dummy PGP keypair for all required PGP keys -- a real production system would
// have different values for these keys. Pass dummy values for all Strings.
return new InMemoryKeyring(
dummyKey,
dummyKey,
dummyKey.getPublicKey(),
dummyKey,
dummyKey.getPublicKey(),
"not a real key",
"not a real key",
"not a real password",
"not a real login",
"not a real password",
"not a real login",
"not a real credential",
"not a real key");
}
开发者ID:google,项目名称:nomulus,代码行数:32,代码来源:DummyKeyringModule.java
示例2: loadSecretKey
import org.bouncycastle.openpgp.bc.BcPGPSecretKeyRingCollection; //导入依赖的package包/类
public static PGPSecretKey loadSecretKey ( final InputStream input, final String keyId ) throws IOException, PGPException
{
final long keyIdNum = Long.parseUnsignedLong ( keyId, 16 );
final BcPGPSecretKeyRingCollection keyrings = new BcPGPSecretKeyRingCollection ( PGPUtil.getDecoderStream ( input ) );
final Iterator<?> keyRingIter = keyrings.getKeyRings ();
while ( keyRingIter.hasNext () )
{
final PGPSecretKeyRing secretKeyRing = (PGPSecretKeyRing)keyRingIter.next ();
final Iterator<?> secretKeyIterator = secretKeyRing.getSecretKeys ();
while ( secretKeyIterator.hasNext () )
{
final PGPSecretKey key = (PGPSecretKey)secretKeyIterator.next ();
if ( !key.isSigningKey () )
{
continue;
}
final long shortId = key.getKeyID () & 0xFFFFFFFFL;
if ( key.getKeyID () != keyIdNum && shortId != keyIdNum )
{
continue;
}
return key;
}
}
return null;
}
开发者ID:eclipse,项目名称:packagedrone,代码行数:35,代码来源:PgpHelper.java
示例3: testEncryptDecrypt_KeyRingStyle
import org.bouncycastle.openpgp.bc.BcPGPSecretKeyRingCollection; //导入依赖的package包/类
@Test
public void testEncryptDecrypt_KeyRingStyle() throws Exception {
int bufferSize = 64 * 1024;
// Alice loads Bob's "publicKey" into memory from her public key ring.
PGPPublicKeyRingCollection publicKeyRings = new BcPGPPublicKeyRingCollection(
PGPUtil.getDecoderStream(new ByteArrayInputStream(PUBLIC_KEY)));
PGPPublicKeyRing publicKeyRing =
publicKeyRings.getKeyRings("[email protected]", true, true).next();
PGPPublicKey publicKey = publicKeyRing.getPublicKey();
// Alice encrypts the secret message for Bob using his "publicKey".
PGPEncryptedDataGenerator encryptor = new PGPEncryptedDataGenerator(
new BcPGPDataEncryptorBuilder(AES_128));
encryptor.addMethod(new BcPublicKeyKeyEncryptionMethodGenerator(publicKey));
byte[] encryptedData;
try (ByteArrayOutputStream output = new ByteArrayOutputStream()) {
try (OutputStream output2 = encryptor.open(output, new byte[bufferSize])) {
output2.write(FALL_OF_HYPERION_A_DREAM.getBytes(UTF_8));
}
encryptedData = output.toByteArray();
}
logger.info("Encrypted data: " + dumpHex(encryptedData));
// Bob loads his chain of private keys into memory.
PGPSecretKeyRingCollection privateKeyRings = new BcPGPSecretKeyRingCollection(
PGPUtil.getDecoderStream(new ByteArrayInputStream(PRIVATE_KEY)));
// Bob decrypt's the OpenPGP message (w/ ciphertext) using his "privateKey".
try (ByteArrayInputStream input = new ByteArrayInputStream(encryptedData)) {
PGPObjectFactory pgpFact = new BcPGPObjectFactory(input);
PGPEncryptedDataList encDataList = (PGPEncryptedDataList) pgpFact.nextObject();
assertThat(encDataList.size()).isEqualTo(1);
PGPPublicKeyEncryptedData encData = (PGPPublicKeyEncryptedData) encDataList.get(0);
// Bob loads the private key to which the message is addressed.
PGPPrivateKey privateKey =
extractPrivateKey(privateKeyRings.getSecretKey(encData.getKeyID()));
try (InputStream original =
encData.getDataStream(new BcPublicKeyDataDecryptorFactory(privateKey))) {
assertThat(CharStreams.toString(new InputStreamReader(original, UTF_8)))
.isEqualTo(FALL_OF_HYPERION_A_DREAM);
}
}
}
开发者ID:google,项目名称:nomulus,代码行数:45,代码来源:BouncyCastleTest.java
示例4: streamKeyring
import org.bouncycastle.openpgp.bc.BcPGPSecretKeyRingCollection; //导入依赖的package包/类
public static Stream<PGPKeyRing> streamKeyring ( final InputStream input ) throws IOException, PGPException
{
final BcPGPSecretKeyRingCollection keyrings = new BcPGPSecretKeyRingCollection ( PGPUtil.getDecoderStream ( input ) );
final Iterator<?> keyRingIter = keyrings.getKeyRings ();
final Stream<?> s = StreamSupport.stream ( Spliterators.spliteratorUnknownSize ( keyRingIter, Spliterator.ORDERED ), false );
return s.map ( o -> (PGPKeyRing)o );
}
开发者ID:eclipse,项目名称:packagedrone,代码行数:11,代码来源:PgpHelper.java
注:本文中的org.bouncycastle.openpgp.bc.BcPGPSecretKeyRingCollection类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论