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


Java PGPObjectFactory.nextObject方法代码示例

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


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

示例1: getEncryptedObjects

import org.bouncycastle.openpgp.PGPObjectFactory; //导入方法依赖的package包/类
@SuppressWarnings( "unchecked" )
private static Iterator<PGPPublicKeyEncryptedData> getEncryptedObjects( final byte[] message ) throws IOException
{
    try
    {
        final PGPObjectFactory factory =
                new PGPObjectFactory( PGPUtil.getDecoderStream( new ByteArrayInputStream( message ) ),
                        new JcaKeyFingerprintCalculator() );
        final Object first = factory.nextObject();
        final Object list = ( first instanceof PGPEncryptedDataList ) ? first : factory.nextObject();
        return ( ( PGPEncryptedDataList ) list ).getEncryptedDataObjects();
    }
    catch ( IOException e )
    {
        throw new IOException( e );
    }
}
 
开发者ID:subutai-io,项目名称:base,代码行数:18,代码来源:PGPEncryptionUtil.java

示例2: getPublicKey

import org.bouncycastle.openpgp.PGPObjectFactory; //导入方法依赖的package包/类
public PGPPublicKeyRing getPublicKey(final InputStream in) {
    Object obj;
    try {
        final PGPObjectFactory pgpFact = new PGPObjectFactory(
                PGPUtil.getDecoderStream(in));
        obj = pgpFact.nextObject();
    }
    catch (final Exception e) {
        throw new IllegalStateException(e);
    }

    if (obj instanceof PGPPublicKeyRing) {
        final PGPPublicKeyRing keyRing = (PGPPublicKeyRing) obj;
        rememberKey(keyRing);
        return keyRing;
    }

    throw new IllegalStateException("Pblic key not available");
}
 
开发者ID:gvSIGAssociation,项目名称:gvnix1,代码行数:20,代码来源:PgpServiceImpl.java

示例3: testCompressDecompress

import org.bouncycastle.openpgp.PGPObjectFactory; //导入方法依赖的package包/类
@Test
public void testCompressDecompress() throws Exception {
  // Compress the data and write out a compressed data OpenPGP message.
  byte[] data;
  try (ByteArrayOutputStream output = new ByteArrayOutputStream()) {
    PGPCompressedDataGenerator kompressor = new PGPCompressedDataGenerator(ZIP);
    try (OutputStream output2 = kompressor.open(output)) {
      output2.write(FALL_OF_HYPERION_A_DREAM.getBytes(UTF_8));
    }
    data = output.toByteArray();
  }
  logger.info("Compressed data: " + dumpHex(data));

  // Decompress the data.
  try (ByteArrayInputStream input = new ByteArrayInputStream(data)) {
    PGPObjectFactory pgpFact = new BcPGPObjectFactory(input);
    PGPCompressedData object = (PGPCompressedData) pgpFact.nextObject();
    InputStream original = object.getDataStream();  // Closing this would close input.
    assertThat(CharStreams.toString(new InputStreamReader(original, UTF_8)))
        .isEqualTo(FALL_OF_HYPERION_A_DREAM);
    assertThat(pgpFact.nextObject()).isNull();
  }
}
 
开发者ID:google,项目名称:nomulus,代码行数:24,代码来源:BouncyCastleTest.java

示例4: verifySignature

import org.bouncycastle.openpgp.PGPObjectFactory; //导入方法依赖的package包/类
/**
 * Verify a PGP signature.
 *
 * @param file the file
 * @param signature the signature
 * @param key the public key
 * @return true if the signature is verified
 * @throws Exception anything preventing the verification to happen
 */
public static boolean verifySignature(
    InputStream file,
    InputStream signature,
    PGPPublicKey key)
    throws Exception {
  InputStream sigInputStream = PGPUtil.getDecoderStream(signature);
  PGPObjectFactory pgpObjectFactory = new PGPObjectFactory(sigInputStream, new BcKeyFingerprintCalculator());
  PGPSignatureList sigList = (PGPSignatureList) pgpObjectFactory.nextObject();
  PGPSignature pgpSignature = sigList.get(0);
  pgpSignature.init(new BcPGPContentVerifierBuilderProvider(), key);
  try (InputStream inArtifact = new BufferedInputStream(file)) {

    int t;
    while ((t = inArtifact.read()) >= 0) {
      pgpSignature.update((byte) t);
    }
  }
  return pgpSignature.verify();
}
 
开发者ID:vert-x3,项目名称:vertx-http-service-factory,代码行数:29,代码来源:PGPHelper.java

示例5: OpenPGPSecretKey

import org.bouncycastle.openpgp.PGPObjectFactory; //导入方法依赖的package包/类
public OpenPGPSecretKey(String keyId, InputStream secretKeyRing, char[] password) throws IOException {
	PGPObjectFactory pgpObjectFactory = new BcPGPObjectFactory(PGPUtil.getDecoderStream(secretKeyRing));

	for (Object it = pgpObjectFactory.nextObject(); it != null; it = pgpObjectFactory.nextObject()) {
		PGPSecretKeyRing pgpSecretKeyRing = (PGPSecretKeyRing) it;
		PGPSecretKey pgpSecretKey = pgpSecretKeyRing.getSecretKey();

		if (keyId == null || keyId.isEmpty() || Long.valueOf(keyId, 16) == (pgpSecretKey.getKeyID() & MASK)) {
			this.secretKey = pgpSecretKey;
			break;
		}
	}

	// sanity check
	if (secretKey == null) {
		throw new IllegalArgumentException("Secret key " + keyId + " not found");
	}

	this.password = password;
}
 
开发者ID:rednoah,项目名称:ant-spk,代码行数:21,代码来源:OpenPGPSecretKey.java

示例6: validateData

import org.bouncycastle.openpgp.PGPObjectFactory; //导入方法依赖的package包/类
private void validateData(byte[] data)
    throws IOException, PGPException
{
    PGPObjectFactory pgpFact = new PGPObjectFactory(data);
    PGPCompressedData c1 = (PGPCompressedData)pgpFact.nextObject();
    InputStream pIn = c1.getDataStream();

    ByteArrayOutputStream bOut = new ByteArrayOutputStream();

    int ch;
    while ((ch = pIn.read()) >= 0)
    {
        bOut.write(ch);
    }

    if (!areEqual(bOut.toByteArray(), "hello world! !dlrow olleh".getBytes()))
    {
        fail("compression test failed");
    }
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:21,代码来源:PGPCompressionTest.java

示例7: readSignatureFile

import org.bouncycastle.openpgp.PGPObjectFactory; //导入方法依赖的package包/类
private PGPSignatureList readSignatureFile(final File signatureFile) throws PGPVerifyException {
	AssertUtil.assertNotNull(signatureFile, "signatureFile");
	if (!signatureFile.isFile() || !signatureFile.canRead())
		throw new PGPVerifyException("The signature-file does not exist or is not readable: " + signatureFile.getAbsolutePath());

	try {
		final InputStream in = new BufferedInputStream(castStream(signatureFile.createInputStream()));
		try {
			final PGPObjectFactory objectFactory = new PGPObjectFactory(
					PGPUtil.getDecoderStream(in), new BcKeyFingerprintCalculator());
			final PGPSignatureList sl = (PGPSignatureList) objectFactory.nextObject();
			return sl;
		} finally {
			in.close();
		}
	} catch (final Exception e) {
		throw new PGPVerifyException(signatureFile.getAbsolutePath() + ": " + e, e);
	}
}
 
开发者ID:cloudstore,项目名称:cloudstore,代码行数:20,代码来源:PGPVerifier.java

示例8: asLiteral

import org.bouncycastle.openpgp.PGPObjectFactory; //导入方法依赖的package包/类
/**
 * ***********************************************
 */
private static PGPLiteralData asLiteral( final InputStream clear ) throws IOException, PGPException
{
    final PGPObjectFactory plainFact = new PGPObjectFactory( clear, new JcaKeyFingerprintCalculator() );
    final Object message = plainFact.nextObject();
    if ( message instanceof PGPCompressedData )
    {
        final PGPCompressedData cData = ( PGPCompressedData ) message;
        final PGPObjectFactory pgpFact =
                new PGPObjectFactory( cData.getDataStream(), new JcaKeyFingerprintCalculator() );
        // Find the first PGPLiteralData object
        Object object = null;
        for ( int safety = 0; ( safety++ < 1000 ) && !( object instanceof PGPLiteralData );
              object = pgpFact.nextObject() )
        {
            //ignore
        }
        return ( PGPLiteralData ) object;
    }
    else if ( message instanceof PGPLiteralData )
    {
        return ( PGPLiteralData ) message;
    }
    else if ( message instanceof PGPOnePassSignatureList )
    {
        throw new PGPException( "encrypted message contains a signed message - not literal data." );
    }
    else
    {
        throw new PGPException(
                "message is not a simple encrypted file - type unknown: " + message.getClass().getName() );
    }
}
 
开发者ID:subutai-io,项目名称:base,代码行数:36,代码来源:PGPEncryptionUtil.java

示例9: pgpExtractSignature

import org.bouncycastle.openpgp.PGPObjectFactory; //导入方法依赖的package包/类
/**
 * Extracts a {@link PGPSignature} object from a blob of {@code .sig} data.
 *
 * @throws SignatureException if a signature object couldn't be extracted for any reason.
 */
private static PGPSignature pgpExtractSignature(@Tainted byte[] signature)
    throws SignatureException {
  try {
    ByteArrayInputStream input = new ByteArrayInputStream(signature);
    PGPObjectFactory decoder = new BcPGPObjectFactory(PGPUtil.getDecoderStream(input));
    Object object = decoder.nextObject();
    if (object == null) {
      throw new SignatureException(String.format(
          "No OpenPGP packets found in signature.\n%s",
          dumpHex(signature)));
    }
    if (!(object instanceof PGPSignatureList)) {
      throw new SignatureException(String.format(
          "Expected PGPSignatureList packet but got %s\n%s",
          object.getClass().getSimpleName(),
          dumpHex(signature)));
    }
    PGPSignatureList sigs = (PGPSignatureList) object;
    if (sigs.isEmpty()) {
      throw new SignatureException(String.format(
          "PGPSignatureList doesn't have a PGPSignature.\n%s",
          dumpHex(signature)));
    }
    return sigs.get(0);
  } catch (IOException e) {
    throw new SignatureException(String.format(
        "Failed to extract PGPSignature object from .sig blob.\n%s",
        dumpHex(signature)), e);
  }
}
 
开发者ID:google,项目名称:nomulus,代码行数:36,代码来源:Marksdb.java

示例10: testSignVerify_Detached

import org.bouncycastle.openpgp.PGPObjectFactory; //导入方法依赖的package包/类
@Test
public void testSignVerify_Detached() throws Exception {
  // Load the keys.
  PGPPublicKeyRing publicKeyRing = new BcPGPPublicKeyRing(PUBLIC_KEY);
  PGPSecretKeyRing privateKeyRing = new BcPGPSecretKeyRing(PRIVATE_KEY);
  PGPPublicKey publicKey = publicKeyRing.getPublicKey();
  PGPPrivateKey privateKey = extractPrivateKey(privateKeyRing.getSecretKey());

  // Sign the data and write signature data to "signatureFile".
  // Note: RSA_GENERAL will encrypt AND sign. RSA_SIGN and RSA_ENCRYPT are deprecated.
  PGPSignatureGenerator signer = new PGPSignatureGenerator(
      new BcPGPContentSignerBuilder(RSA_GENERAL, SHA256));
  signer.init(PGPSignature.BINARY_DOCUMENT, privateKey);
  addUserInfoToSignature(publicKey, signer);
  signer.update(FALL_OF_HYPERION_A_DREAM.getBytes(UTF_8));
  ByteArrayOutputStream output = new ByteArrayOutputStream();
  signer.generate().encode(output);
  byte[] signatureFileData = output.toByteArray();
  logger.info(".sig file data: " + dumpHex(signatureFileData));

  // Load algorithm information and signature data from "signatureFileData".
  PGPSignature sig;
  try (ByteArrayInputStream input = new ByteArrayInputStream(signatureFileData)) {
    PGPObjectFactory pgpFact = new BcPGPObjectFactory(input);
    PGPSignatureList sigList = (PGPSignatureList) pgpFact.nextObject();
    assertThat(sigList.size()).isEqualTo(1);
    sig = sigList.get(0);
  }

  // Use "onePass" and "sig" to verify "publicKey" signed the text.
  sig.init(new BcPGPContentVerifierBuilderProvider(), publicKey);
  sig.update(FALL_OF_HYPERION_A_DREAM.getBytes(UTF_8));
  assertThat(sig.verify()).isTrue();

  // Verify that they DIDN'T sign the text "hello monster".
  sig.init(new BcPGPContentVerifierBuilderProvider(), publicKey);
  sig.update("hello monster".getBytes(UTF_8));
  assertThat(sig.verify()).isFalse();
}
 
开发者ID:google,项目名称:nomulus,代码行数:40,代码来源:BouncyCastleTest.java

示例11: testEncryptDecrypt_ExplicitStyle

import org.bouncycastle.openpgp.PGPObjectFactory; //导入方法依赖的package包/类
@Test
public void testEncryptDecrypt_ExplicitStyle() throws Exception {
  int bufferSize = 64 * 1024;

  // Alice loads Bob's "publicKey" into memory.
  PGPPublicKeyRing publicKeyRing = new BcPGPPublicKeyRing(PUBLIC_KEY);
  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 "privateKey" into memory.
  PGPSecretKeyRing privateKeyRing = new BcPGPSecretKeyRing(PRIVATE_KEY);
  PGPPrivateKey privateKey = extractPrivateKey(privateKeyRing.getSecretKey());

  // 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);
    assertThat(encData.getKeyID()).isEqualTo(publicKey.getKeyID());
    assertThat(encData.getKeyID()).isEqualTo(privateKey.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,代码行数:41,代码来源:BouncyCastleTest.java

示例12: verifySignature

import org.bouncycastle.openpgp.PGPObjectFactory; //导入方法依赖的package包/类
private void verifySignature(PGPObjectFactory pgpFactory, PGPOnePassSignature signature) throws IOException, PGPException, SignatureException {
    if (signature != null) {
        PGPSignatureList sigList = (PGPSignatureList) pgpFactory.nextObject();
        if (!signature.verify(getSignatureWithKeyId(signature.getKeyID(), sigList))) {
            throw new SignatureException("Verification of the PGP signature with the key ID " + signature.getKeyID() + " failed. The PGP message may have been tampered.");
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:9,代码来源:PGPKeyAccessDataFormat.java

示例13: readSignature

import org.bouncycastle.openpgp.PGPObjectFactory; //导入方法依赖的package包/类
private PGPSignature readSignature(PushCertificate cert) throws IOException {
  ArmoredInputStream in =
      new ArmoredInputStream(new ByteArrayInputStream(Constants.encode(cert.getSignature())));
  PGPObjectFactory factory = new BcPGPObjectFactory(in);
  Object obj;
  while ((obj = factory.nextObject()) != null) {
    if (obj instanceof PGPSignatureList) {
      PGPSignatureList sigs = (PGPSignatureList) obj;
      if (!sigs.isEmpty()) {
        return sigs.get(0);
      }
    }
  }
  return null;
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:16,代码来源:PushCertificateChecker.java

示例14: importKeys

import org.bouncycastle.openpgp.PGPObjectFactory; //导入方法依赖的package包/类
@Override
public synchronized ImportKeysResult importKeys(IInputStream _in) {
	assertNotNull(_in, "in");

	InputStream in = castStream(_in);

	final ImportKeysResult importKeysResult = new ImportKeysResult();
	boolean modified = false;
	try {
		in = PGPUtil.getDecoderStream(in);
		final PGPObjectFactory pgpF = new PGPObjectFactory(in, new BcKeyFingerprintCalculator());

		Object o;
		while ((o = pgpF.nextObject()) != null) {
			if (o instanceof PGPPublicKeyRing)
				modified |= importPublicKeyRing(importKeysResult, (PGPPublicKeyRing) o);
			else if (o instanceof PGPSecretKeyRing)
				modified |= importSecretKeyRing(importKeysResult, (PGPSecretKeyRing) o);
			else
				throw new IllegalStateException("Unexpected object in InputStream (only PGPPublicKeyRing and PGPSecretKeyRing are supported): " + o);
		}
	} catch (IOException | PGPException x) {
		throw new RuntimeException(x);
	}

	if (modified) // make sure the localRevision is incremented, even if the timestamp does not change (e.g. because the time resolution of the file system is too low).
		incLocalRevision();

	return importKeysResult;
}
 
开发者ID:subshare,项目名称:subshare,代码行数:31,代码来源:BcWithLocalGnuPgPgp.java

示例15: extractPGPObject

import org.bouncycastle.openpgp.PGPObjectFactory; //导入方法依赖的package包/类
public static <T> T extractPGPObject(final Class<T> type, final InputStream inputStream) throws IOException {
  final PGPObjectFactory objectFactory = new PGPObjectFactory(new ArmoredInputStream(inputStream), new BcKeyFingerprintCalculator());
  Object object;
  while ((object = objectFactory.nextObject()) != null) {
    if (type.isAssignableFrom(object.getClass())) {
      return type.cast(object);
    }
  }
  throw new IllegalArgumentException("Input text does not contain a PGP object");
}
 
开发者ID:hsch,项目名称:bcpg-simple,代码行数:11,代码来源:BcPGPUtils.java


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