本文整理汇总了Java中org.bouncycastle.openpgp.PGPPublicKeyRingCollection.size方法的典型用法代码示例。如果您正苦于以下问题:Java PGPPublicKeyRingCollection.size方法的具体用法?Java PGPPublicKeyRingCollection.size怎么用?Java PGPPublicKeyRingCollection.size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.openpgp.PGPPublicKeyRingCollection
的用法示例。
在下文中一共展示了PGPPublicKeyRingCollection.size方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: saveToNotes
import org.bouncycastle.openpgp.PGPPublicKeyRingCollection; //导入方法依赖的package包/类
private void saveToNotes(ObjectInserter ins, PGPPublicKeyRing keyRing)
throws PGPException, IOException {
long keyId = keyRing.getPublicKey().getKeyID();
PGPPublicKeyRingCollection existing = get(keyId);
List<PGPPublicKeyRing> toWrite = new ArrayList<>(existing.size() + 1);
boolean replaced = false;
for (PGPPublicKeyRing kr : existing) {
if (sameKey(keyRing, kr)) {
toWrite.add(keyRing);
replaced = true;
} else {
toWrite.add(kr);
}
}
if (!replaced) {
toWrite.add(keyRing);
}
notes.set(keyObjectId(keyId), ins.insert(OBJ_BLOB, keysToArmored(toWrite)));
}
示例2: deleteFromNotes
import org.bouncycastle.openpgp.PGPPublicKeyRingCollection; //导入方法依赖的package包/类
private void deleteFromNotes(ObjectInserter ins, Fingerprint fp)
throws PGPException, IOException {
long keyId = fp.getId();
PGPPublicKeyRingCollection existing = get(keyId);
List<PGPPublicKeyRing> toWrite = new ArrayList<>(existing.size());
for (PGPPublicKeyRing kr : existing) {
if (!fp.equalsBytes(kr.getPublicKey().getFingerprint())) {
toWrite.add(kr);
}
}
if (toWrite.size() == existing.size()) {
return;
} else if (!toWrite.isEmpty()) {
notes.set(keyObjectId(keyId), ins.insert(OBJ_BLOB, keysToArmored(toWrite)));
} else {
notes.remove(keyObjectId(keyId));
}
}
示例3: if
import org.bouncycastle.openpgp.PGPPublicKeyRingCollection; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private final static List<Result> validate
(CHkpSearch.Info candidate, String q, IGetter getter)
throws IOException
{
List<Result> ret = new ArrayList<Result>();
if (shouldSkip(candidate, q)) { return ret; }
// 1. pull down keys from the candidate.
PGPPublicKeyRingCollection pkrc = CHkpSearch.get
(candidate.getKeyId(), getter);
if ((pkrc == null) || (pkrc.size() <= 0)) {
return ret;
}
// 2. Validate each keyring.
Iterator<PGPPublicKeyRing> pkrit = pkrc.getKeyRings();
while (pkrit.hasNext()) {
Result r = validateKeyRing(pkrit.next(), q, getter);
if (r != null) { ret.add(r); }
}
return ret;
}
示例4: validateLicense
import org.bouncycastle.openpgp.PGPPublicKeyRingCollection; //导入方法依赖的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);
}
}