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