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


Java PGPSignatureList.size方法代码示例

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


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

示例1: 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

示例2: 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

示例3: getPgpSignature

import org.bouncycastle.openpgp.PGPSignatureList; //导入方法依赖的package包/类
private PGPSignature getPgpSignature() {
    try {
        final InputStream decoderStream = PGPUtil.getDecoderStream(new ByteArrayInputStream(signature));
        final PGPObjectFactory objectFactory = new BcPGPObjectFactory(decoderStream);

        final PGPSignatureList signatureList = (PGPSignatureList) objectFactory.nextObject();
        if ((signatureList == null) || (signatureList.size() != 1)) {
            throw new IllegalArgumentException("Couldn't read PGP signature");
        }

        return signatureList.get(0);
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    }
}
 
开发者ID:RIPE-NCC,项目名称:whois,代码行数:16,代码来源:PgpSignedMessage.java

示例4: validateLicense

import org.bouncycastle.openpgp.PGPSignatureList; //导入方法依赖的package包/类
/**
 * Validate pgp signature of license
 * 
 * @param licenseText base64 encoded pgp signed license
 * @return The plain license in json (if validation is successful)
 * @throws PGPException if validation fails
 */
public static String validateLicense(String licenseText) throws PGPException {
    
	licenseText = licenseText.trim().replaceAll("\\r|\\n", "");
    licenseText = licenseText.replace("---- SCHNIPP (Armored PGP signed JSON as base64) ----","");
    licenseText = licenseText.replace("---- SCHNAPP ----","");
    
    try {
        final byte[] armoredPgp = BaseEncoding.base64().decode(licenseText);

        final ArmoredInputStream in = new ArmoredInputStream(new ByteArrayInputStream(armoredPgp));

        //
        // read the input, making sure we ignore the last newline.
        //
        // https://github.com/bcgit/bc-java/blob/master/pg/src/test/java/org/bouncycastle/openpgp/test/PGPClearSignedSignatureTest.java

        final ByteArrayOutputStream bout = new ByteArrayOutputStream();
        int ch;

        while ((ch = in.read()) >= 0 && in.isClearText()) {
            bout.write((byte) ch);
        }

        final KeyFingerPrintCalculator c = new BcKeyFingerprintCalculator();

        final PGPObjectFactory factory = new PGPObjectFactory(in, c);
        final PGPSignatureList sigL = (PGPSignatureList) factory.nextObject();
        final PGPPublicKeyRingCollection pgpRings = new PGPPublicKeyRingCollection(new ArmoredInputStream(
                LicenseHelper.class.getResourceAsStream("/KEYS")), c);

        if (sigL == null || pgpRings == null || sigL.size() == 0 || pgpRings.size() == 0) {
            throw new PGPException("Cannot find license signature");
        }

        final PGPSignature sig = sigL.get(0);
        final PGPPublicKey publicKey = pgpRings.getPublicKey(sig.getKeyID());

        if (publicKey == null || sig == null) {
            throw new PGPException("license signature key mismatch");
        }

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

        final ByteArrayOutputStream lineOut = new ByteArrayOutputStream();
        final InputStream sigIn = new ByteArrayInputStream(bout.toByteArray());
        int lookAhead = readInputLine(lineOut, sigIn);

        processLine(sig, lineOut.toByteArray());

        if (lookAhead != -1) {
            do {
                lookAhead = readInputLine(lineOut, lookAhead, sigIn);

                sig.update((byte) '\r');
                sig.update((byte) '\n');

                processLine(sig, lineOut.toByteArray());
            } while (lookAhead != -1);
        }

        if (!sig.verify()) {
            throw new PGPException("Invalid license signature");
        }

        return bout.toString();
    } catch (final Exception e) {
        throw new PGPException(e.toString(), e);
    }
}
 
开发者ID:floragunncom,项目名称:search-guard,代码行数:77,代码来源:LicenseHelper.java


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