ASCII- 기갑 OpenPGP 공개 키가 여러 개인 텍스트 파일이 있습니다. Bouncy Castle을 사용하여이 파일에 포함 된 모든 공개 키로 문자열을 암호화하려고합니다. 나는 PGPPublicKeyRingCollection
로 파일을로드 할 때, 첫 번째 키가 반환됩니다Bouncy Castle PGP를 사용하여 하나의 파일에서 여러 공개 키로드
private static List<PGPPublicKey> readPublicKeys(InputStream input) throws IOException, PGPException {
PGPPublicKeyRingCollection pgpPub = new PGPPublicKeyRingCollection(PGPUtil.getDecoderStream(input), new JcaKeyFingerprintCalculator());
List<PGPPublicKey> keys = new ArrayList<>();
// size is 1 here
logger.debug("size " + pgpPub.size());
@SuppressWarnings("unchecked")
Iterator<PGPPublicKeyRing> keyRingIter = pgpPub.getKeyRings();
while (keyRingIter.hasNext()) {
PGPPublicKeyRing keyRing = keyRingIter.next();
@SuppressWarnings("unchecked")
Iterator<PGPPublicKey> keyIter = keyRing.getPublicKeys();
while (keyIter.hasNext()) {
PGPPublicKey key = keyIter.next();
// there is only ever 1 key here as well
if (key.isEncryptionKey()) {
keys.add(key);
}
}
}
if (keys.size() > 0) {
return keys;
} else {
throw new IllegalArgumentException("Can't find encryption key in key ring.");
}
}
오전 내가 모르는 뭔가가?
FWIW, $ gpg --dry-run my.keys
을 실행하면 올바르게 7 개의 공개 키를 모두 감지하여 지문을 출력합니다.