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


Java PGPSignatureList类代码示例

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


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

示例1: verify

import org.bouncycastle.openpgp.PGPSignatureList; //导入依赖的package包/类
/**
 * Verify a signature. Only return true if signature matches calculated signature of signedData
 * and if it was signed by the publicKey
 *
 * @param signedData
 * @param signature
 * @return
 */
public boolean verify(InputStream signedData, InputStream signature) {
    try {
        signature = PGPUtil.getDecoderStream(signature);
        JcaPGPObjectFactory pgpFact = new JcaPGPObjectFactory(signature);
        PGPSignature sig = ((PGPSignatureList) pgpFact.nextObject()).get(0);
        PGPPublicKey key = pgpPubRingCollection.getPublicKey(sig.getKeyID());
        sig.init(new JcaPGPContentVerifierBuilderProvider().setProvider("BC"), key);
        byte[] buff = new byte[1024];
        int read = 0;
        while ((read = signedData.read(buff)) != -1) {
            sig.update(buff, 0, read);
        }
        signedData.close();
        return sig.verify();
    }
    catch (Exception ex) {
        // can we put a logger here please?
        return false;
    }
}
 
开发者ID:atomist-attic,项目名称:rug-resolver,代码行数:29,代码来源:GpgSignatureVerifier.java

示例2: verifySignature

import org.bouncycastle.openpgp.PGPSignatureList; //导入依赖的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

示例3: readSignatureFile

import org.bouncycastle.openpgp.PGPSignatureList; //导入依赖的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

示例4: verifyGoodSignature

import org.bouncycastle.openpgp.PGPSignatureList; //导入依赖的package包/类
@Test
public void verifyGoodSignature() throws Exception {
	final PGPPublicKeyRingCollection publicKeyRing = getPublicKeyRingWithTrustedKeys();

	final PGPSignatureList sl = readSignatureFile("/content1.sig");
	assertThat(sl.isEmpty()).isFalse();
	assertThat(sl.size()).isEqualTo(1);

	PGPSignature signature = sl.get(0);
	signature.init(new BcPGPContentVerifierBuilderProvider(), publicKeyRing.getPublicKey(signature.getKeyID()));

	InputStream contentIn = PGPTest.class.getResourceAsStream("/content1");
	byte[] buf = new byte[4096];
	int len;
	while (0 <= (len = contentIn.read(buf))) {
		signature.update(buf, 0, len);
	}
	contentIn.close();
	assertThat(signature.verify()).isTrue();
}
 
开发者ID:cloudstore,项目名称:cloudstore,代码行数:21,代码来源:PGPTest.java

示例5: verifyBadSignature

import org.bouncycastle.openpgp.PGPSignatureList; //导入依赖的package包/类
@Test
public void verifyBadSignature() throws Exception {
	final PGPPublicKeyRingCollection publicKeyRing = getPublicKeyRingWithTrustedKeys();

	final PGPSignatureList sl = readSignatureFile("/content1.sig");
	assertThat(sl.isEmpty()).isFalse();
	assertThat(sl.size()).isEqualTo(1);

	PGPSignature signature = sl.get(0);
	signature.init(new BcPGPContentVerifierBuilderProvider(), publicKeyRing.getPublicKey(signature.getKeyID()));

	InputStream contentIn = PGPTest.class.getResourceAsStream("/content1");
	byte[] buf = new byte[4096];
	int len;
	while (0 <= (len = contentIn.read(buf))) {
		buf[0] = 0;
		signature.update(buf, 0, len);
	}
	contentIn.close();
	assertThat(signature.verify()).isFalse();
}
 
开发者ID:cloudstore,项目名称:cloudstore,代码行数:22,代码来源:PGPTest.java

示例6: ContentAndSignatures

import org.bouncycastle.openpgp.PGPSignatureList; //导入依赖的package包/类
public ContentAndSignatures( final byte[] decryptedContent, final PGPOnePassSignatureList onePassSignatureList,
                             final PGPSignatureList signatureList )
{

    this.decryptedContent = decryptedContent;
    this.onePassSignatureList = onePassSignatureList;
    this.signatureList = signatureList;
}
 
开发者ID:subutai-io,项目名称:base,代码行数:9,代码来源:ContentAndSignatures.java

示例7: doVerify

import org.bouncycastle.openpgp.PGPSignatureList; //导入依赖的package包/类
private static void doVerify( JcaPGPObjectFactory objectFactory, PGPOnePassSignature onePassSignature )
        throws IOException, PGPException
{
    PGPSignatureList signatures = ( PGPSignatureList ) objectFactory.nextObject();

    if ( !onePassSignature.verify( signatures.get( 0 ) ) )
    {
        throw new PGPDataValidationException( "Signature verification failed" );
    }
}
 
开发者ID:subutai-io,项目名称:base,代码行数:11,代码来源:PGPVerify.java

示例8: pgpExtractSignature

import org.bouncycastle.openpgp.PGPSignatureList; //导入依赖的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

示例9: testSignVerify_Detached

import org.bouncycastle.openpgp.PGPSignatureList; //导入依赖的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

示例10: verifySignature

import org.bouncycastle.openpgp.PGPSignatureList; //导入依赖的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

示例11: getSignatureWithKeyId

import org.bouncycastle.openpgp.PGPSignatureList; //导入依赖的package包/类
protected PGPSignature getSignatureWithKeyId(long keyID, PGPSignatureList sigList) {
    for (int i = 0; i < sigList.size(); i++) {
        PGPSignature signature = sigList.get(i);
        if (keyID == signature.getKeyID()) {
            return signature;
        }
    }
    throw new IllegalStateException("PGP signature is inconsistent");
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:10,代码来源:PGPKeyAccessDataFormat.java

示例12: readSignature

import org.bouncycastle.openpgp.PGPSignatureList; //导入依赖的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

示例13: revocationTest

import org.bouncycastle.openpgp.PGPSignatureList; //导入依赖的package包/类
public void revocationTest()
    throws Exception
{
    PGPPublicKeyRing    pgpPub = new PGPPublicKeyRing(pub7, new BcKeyFingerprintCalculator());
    Iterator            it = pgpPub.getPublicKeys();
    PGPPublicKey        masterKey = null;

    while (it.hasNext())
    {
        PGPPublicKey    k = (PGPPublicKey)it.next();

        if (k.isMasterKey())
        {
            masterKey = k;
            continue;
        }
    }

    PGPSignature    sig =((PGPSignatureList)new PGPObjectFactory(pub7revoke).nextObject()).get(0);

    sig.init(new BcPGPContentVerifierBuilderProvider(), masterKey);

    if (!sig.verifyCertification(masterKey))
    {
        fail("failed to verify revocation certification");
    }
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:28,代码来源:BcPGPKeyRingTest.java

示例14: verifySignature

import org.bouncycastle.openpgp.PGPSignatureList; //导入依赖的package包/类
private static DecryptionResult verifySignature(DecryptionResult result,
        PGPObjectFactory pgpFact, PGPOnePassSignature ops) throws PGPException, IOException {
    Object object = pgpFact.nextObject(); // nullable
    if (!(object instanceof PGPSignatureList)) {
        LOGGER.warning("invalid signature packet");
        result.errors.add(Coder.Error.INVALID_SIGNATURE_DATA);
        return result;
    }

    PGPSignatureList signatureList = (PGPSignatureList) object;
    if (signatureList.isEmpty()) {
        LOGGER.warning("no signature in signature list");
        result.errors.add(Coder.Error.INVALID_SIGNATURE_DATA);
        return result;
    }

    PGPSignature signature = signatureList.get(0);
    // TODO signature.getCreationTime()
    if (ops.verify(signature)) {
        // signature verification successful!
        result.signing = Coder.Signing.VERIFIED;
    } else {
        LOGGER.warning("signature verification failed");
        result.errors.add(Coder.Error.INVALID_SIGNATURE);
    }
    return result;
}
 
开发者ID:kontalk,项目名称:desktopclient-java,代码行数:28,代码来源:Decryptor.java

示例15: verify

import org.bouncycastle.openpgp.PGPSignatureList; //导入依赖的package包/类
/**
 * Verify the specified {@code file}.
 * @param file the file to be verified. Must not be <code>null</code>. There must be a second file
 * with the same name and the additional suffix ".sig" next to this file (in the same directory).
 * This secondary file is a so-called detached signature.
 * @throws PGPVerifyException if the given {@code file} could not be verified successfully. Either
 * there is no detached-signature-file, or its signature is broken or its signature does not match
 * any of the {@linkplain #getPublicKeyRingWithTrustedKeys() trusted keys}.
 */
public void verify(final File file, final File signatureFile) throws PGPVerifyException {
	AssertUtil.assertNotNull(file, "file");
	AssertUtil.assertNotNull(signatureFile, "signatureFile");

	final PGPSignatureList sl = readSignatureFile(signatureFile);
	final PGPPublicKeyRingCollection publicKeyRing = getPublicKeyRingWithTrustedKeys();

	for (int index = 0; index < sl.size(); ++index) {
		try {
			final PGPSignature signature = sl.get(index);
			signature.init(new BcPGPContentVerifierBuilderProvider(), publicKeyRing.getPublicKey(signature.getKeyID()));

			final InputStream contentIn = castStream(file.createInputStream());
			try {
				final byte[] buf = new byte[16 * 1024];
				int len;
				while (0 <= (len = contentIn.read(buf))) {
					if (len > 0)
						signature.update(buf, 0, len);
				}
			} finally {
				contentIn.close();
			}

			if (signature.verify())
				return;

		} catch (final Exception e) {
			throw new PGPVerifyException(file.getAbsolutePath() + ": " + e, e);
		}
	}
	throw new PGPVerifyException(file.getAbsolutePath());
}
 
开发者ID:cloudstore,项目名称:cloudstore,代码行数:43,代码来源:PGPVerifier.java


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