本文整理汇总了Java中org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator类的典型用法代码示例。如果您正苦于以下问题:Java BcKeyFingerprintCalculator类的具体用法?Java BcKeyFingerprintCalculator怎么用?Java BcKeyFingerprintCalculator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BcKeyFingerprintCalculator类属于org.bouncycastle.openpgp.operator.bc包,在下文中一共展示了BcKeyFingerprintCalculator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readSecretKey
import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator; //导入依赖的package包/类
static PGPSecretKey readSecretKey() throws Exception {
InputStream input = new ByteArrayInputStream(getSecKeyRing());
PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(PGPUtil.getDecoderStream(input),
new BcKeyFingerprintCalculator());
@SuppressWarnings("rawtypes")
Iterator keyRingIter = pgpSec.getKeyRings();
while (keyRingIter.hasNext()) {
PGPSecretKeyRing keyRing = (PGPSecretKeyRing) keyRingIter.next();
@SuppressWarnings("rawtypes")
Iterator keyIter = keyRing.getSecretKeys();
while (keyIter.hasNext()) {
PGPSecretKey key = (PGPSecretKey) keyIter.next();
if (key.isSigningKey()) {
return key;
}
}
}
throw new IllegalArgumentException("Can't find signing key in key ring.");
}
示例2: test11
import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator; //导入依赖的package包/类
private void test11()
throws Exception
{
PGPPublicKeyRing pubRing = new PGPPublicKeyRing(subKeyBindingKey, new BcKeyFingerprintCalculator());
Iterator it = pubRing.getPublicKeys();
while (it.hasNext())
{
PGPPublicKey key = (PGPPublicKey)it.next();
if (key.getValidSeconds() != 0)
{
fail("expiration time non-zero");
}
}
}
示例3: checkSecretKeyRingWithPersonalCertificate
import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator; //导入依赖的package包/类
private void checkSecretKeyRingWithPersonalCertificate(byte[] keyRing)
throws Exception
{
PGPSecretKeyRingCollection secCol = new PGPSecretKeyRingCollection(keyRing, new BcKeyFingerprintCalculator());
int count = 0;
for (Iterator rIt = secCol.getKeyRings(); rIt.hasNext();)
{
PGPSecretKeyRing ring = (PGPSecretKeyRing)rIt.next();
for (Iterator it = ring.getExtraPublicKeys(); it.hasNext();)
{
it.next();
count++;
}
}
if (count != 1)
{
fail("personal certificate data subkey not found - count = " + count);
}
}
示例4: getKey
import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator; //导入依赖的package包/类
public PGPPublicKey getKey(long keyID) throws IOException, PGPException {
File keyFile = null;
PGPPublicKey key = null;
try {
String path = String.format("%02X/%02X/%016X.asc",
(byte) (keyID >> 56), (byte) (keyID >> 48 & 0xff), keyID);
keyFile = new File(cachePath, path);
if (!keyFile.exists()) {
receiveKey(keyFile, keyID);
}
InputStream keyIn = PGPUtil.getDecoderStream(new FileInputStream(keyFile));
PGPPublicKeyRingCollection pgpRing = new PGPPublicKeyRingCollection(keyIn, new BcKeyFingerprintCalculator());
key = pgpRing.getPublicKey(keyID);
} finally {
if (key == null) {
deleteFile(keyFile);
}
}
return key;
}
示例5: readPublicKey
import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator; //导入依赖的package包/类
static PGPPublicKey readPublicKey(String keyringPath) throws Exception {
InputStream input = new ByteArrayInputStream(getKeyRing(keyringPath));
PGPPublicKeyRingCollection pgpPub = new PGPPublicKeyRingCollection(PGPUtil.getDecoderStream(input),
new BcKeyFingerprintCalculator());
@SuppressWarnings("rawtypes")
Iterator keyRingIter = pgpPub.getKeyRings();
while (keyRingIter.hasNext()) {
PGPPublicKeyRing keyRing = (PGPPublicKeyRing) keyRingIter.next();
@SuppressWarnings("rawtypes")
Iterator keyIter = keyRing.getPublicKeys();
while (keyIter.hasNext()) {
PGPPublicKey key = (PGPPublicKey) keyIter.next();
if (key.isEncryptionKey()) {
return key;
}
}
}
throw new IllegalArgumentException("Can't find encryption key in key ring.");
}
示例6: readPublicKeyRing
import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator; //导入依赖的package包/类
/**
* reads the public key ring from the input stream
*
* @param publicKey
* the public key stream
* @return the public key ring
*/
protected PGPPublicKeyRing readPublicKeyRing(InputStream publicKey) {
LOGGER.trace("readPublicKeyRing(InputStream)");
PGPPublicKeyRing result = null;
LOGGER.debug("Wrapping public key stream in decoder stream");
try( InputStream decoderStream = PGPUtil.getDecoderStream(publicKey) ) {
LOGGER.debug("Creating PGP Object Factory");
PGPObjectFactory pgpObjectFactory = new PGPObjectFactory(decoderStream, new BcKeyFingerprintCalculator());
Object o = null;
LOGGER.debug("Looking up PGP Public KeyRing");
while( (o = pgpObjectFactory.nextObject()) != null && result == null ) {
if( o instanceof PGPPublicKeyRing ) {
LOGGER.info("PGP Public KeyRing retrieved");
result = (PGPPublicKeyRing)o;
}
}
} catch (IOException e) {
LOGGER.error("{}", e.getMessage());
}
return result;
}
示例7: verifySignature
import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator; //导入依赖的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();
}
示例8: testExpiry
import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator; //导入依赖的package包/类
private void testExpiry(
byte[] encodedRing,
int masterDays,
int subKeyDays)
throws Exception
{
PGPPublicKeyRing pubRing = new PGPPublicKeyRing(encodedRing, new BcKeyFingerprintCalculator());
PGPPublicKey k = pubRing.getPublicKey();
if (k.getValidDays() != masterDays)
{
fail("mismatch on master valid days.");
}
Iterator it = pubRing.getPublicKeys();
it.next();
k = (PGPPublicKey)it.next();
if (k.getValidDays() != subKeyDays)
{
fail("mismatch on subkey valid days.");
}
}
示例9: getKey
import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator; //导入依赖的package包/类
PGPPublicKey getKey(long keyID) throws IOException, PGPException {
File keyFile = null;
PGPPublicKey key = null;
try {
String path = String.format("%02X/%02X/%016X.asc",
(byte) (keyID >> 56), (byte) (keyID >> 48 & 0xff), keyID);
keyFile = new File(cachePath, path);
if (!keyFile.exists()) {
receiveKey(keyFile, keyID);
}
InputStream keyIn = PGPUtil.getDecoderStream(new FileInputStream(keyFile));
PGPPublicKeyRingCollection pgpRing = new PGPPublicKeyRingCollection(keyIn, new BcKeyFingerprintCalculator());
key = pgpRing.getPublicKey(keyID);
} finally {
if (key == null) {
deleteFile(keyFile);
}
}
return key;
}
示例10: asLiteral
import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator; //导入依赖的package包/类
private static PGPLiteralData asLiteral(
final byte[] data,
final InputStream keyfile,
final String passphrase) throws IOException, PGPException {
PGPPrivateKey key = null;
PGPPublicKeyEncryptedData encrypted = null;
final PGPSecretKeyRingCollection keys =
new PGPSecretKeyRingCollection(new ArmoredInputStream(keyfile), new BcKeyFingerprintCalculator());
for (final Iterator<PGPPublicKeyEncryptedData> i = getEncryptedObjects(data); key == null && i.hasNext();) {
encrypted = i.next();
key = findSecretKey(keys, encrypted.getKeyID(), passphrase);
}
if (key == null) {
throw new IllegalArgumentException("secret key for message not found.");
}
final InputStream stream = encrypted.getDataStream(
new JcePublicKeyDataDecryptorFactoryBuilder()
.setProvider(PROVIDER)
.build(key));
return asLiteral(stream);
}
示例11: readSignatureFile
import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator; //导入依赖的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);
}
}
示例12: test6
import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator; //导入依赖的package包/类
public void test6()
throws Exception
{
PGPPublicKeyRingCollection pubRings = new PGPPublicKeyRingCollection(pub6, new BcKeyFingerprintCalculator());
Iterator rIt = pubRings.getKeyRings();
while (rIt.hasNext())
{
PGPPublicKeyRing pgpPub = (PGPPublicKeyRing)rIt.next();
Iterator it = pgpPub.getPublicKeys();
while (it.hasNext())
{
PGPPublicKey k = (PGPPublicKey)it.next();
if (k.getKeyID() == 0x5ce086b5b5a18ff4L)
{
int count = 0;
Iterator sIt = k.getSignaturesOfType(PGPSignature.SUBKEY_REVOCATION);
while (sIt.hasNext())
{
PGPSignature sig = (PGPSignature)sIt.next();
count++;
}
if (count != 1)
{
fail("wrong number of revocations in test6.");
}
}
}
}
byte[] encRing = pubRings.getEncoded();
}
示例13: rewrapTest
import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator; //导入依赖的package包/类
private void rewrapTest()
throws Exception
{
SecureRandom rand = new SecureRandom();
// Read the secret key rings
PGPSecretKeyRingCollection privRings = new PGPSecretKeyRingCollection(
new ByteArrayInputStream(rewrapKey), new BcKeyFingerprintCalculator());
Iterator rIt = privRings.getKeyRings();
if (rIt.hasNext())
{
PGPSecretKeyRing pgpPriv = (PGPSecretKeyRing)rIt.next();
Iterator it = pgpPriv.getSecretKeys();
while (it.hasNext())
{
PGPSecretKey pgpKey = (PGPSecretKey)it.next();
// re-encrypt the key with an empty password
pgpPriv = PGPSecretKeyRing.removeSecretKey(pgpPriv, pgpKey);
pgpKey = PGPSecretKey.copyWithNewPassword(
pgpKey,
new BcPBESecretKeyDecryptorBuilder(new BcPGPDigestCalculatorProvider()).build(rewrapPass),
null);
pgpPriv = PGPSecretKeyRing.insertSecretKey(pgpPriv, pgpKey);
// this should succeed
PGPPrivateKey privTmp = pgpKey.extractPrivateKey(null);
}
}
}
示例14: testPublicKeyRingWithX509
import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator; //导入依赖的package包/类
private void testPublicKeyRingWithX509()
throws Exception
{
checkPublicKeyRingWithX509(pubWithX509);
PGPPublicKeyRing pubRing = new PGPPublicKeyRing(pubWithX509, new BcKeyFingerprintCalculator());
checkPublicKeyRingWithX509(pubRing.getEncoded());
}
示例15: testSecretKeyRingWithPersonalCertificate
import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator; //导入依赖的package包/类
private void testSecretKeyRingWithPersonalCertificate()
throws Exception
{
checkSecretKeyRingWithPersonalCertificate(secWithPersonalCertificate);
PGPSecretKeyRingCollection secRing = new PGPSecretKeyRingCollection(secWithPersonalCertificate, new BcKeyFingerprintCalculator());
checkSecretKeyRingWithPersonalCertificate(secRing.getEncoded());
}