當前位置: 首頁>>代碼示例>>Java>>正文


Java PGPUtil.getDecoderStream方法代碼示例

本文整理匯總了Java中org.bouncycastle.openpgp.PGPUtil.getDecoderStream方法的典型用法代碼示例。如果您正苦於以下問題:Java PGPUtil.getDecoderStream方法的具體用法?Java PGPUtil.getDecoderStream怎麽用?Java PGPUtil.getDecoderStream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.bouncycastle.openpgp.PGPUtil的用法示例。


在下文中一共展示了PGPUtil.getDecoderStream方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: asLiteral

import org.bouncycastle.openpgp.PGPUtil; //導入方法依賴的package包/類
private static PGPLiteralData asLiteral( final byte[] message, final InputStream secretKeyRing,
                                         final String secretPwd ) throws IOException, PGPException
{
    PGPPrivateKey key = null;
    PGPPublicKeyEncryptedData encrypted = null;
    final PGPSecretKeyRingCollection keys =
            new PGPSecretKeyRingCollection( PGPUtil.getDecoderStream( secretKeyRing ),
                    new JcaKeyFingerprintCalculator() );
    for ( final Iterator<PGPPublicKeyEncryptedData> i = getEncryptedObjects( message );
          ( key == null ) && i.hasNext(); )
    {
        encrypted = i.next();
        key = getPrivateKey( keys, encrypted.getKeyID(), secretPwd );
    }
    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 );
}
 
開發者ID:subutai-io,項目名稱:base,代碼行數:23,代碼來源:PGPEncryptionUtil.java

示例2: readPublicKey

import org.bouncycastle.openpgp.PGPUtil; //導入方法依賴的package包/類
public static PGPPublicKey readPublicKey(InputStream in)
   throws IOException, PGPException {
in = PGPUtil.getDecoderStream(in);

PGPPublicKeyRingCollection pgpPub = new PGPPublicKeyRingCollection(in, new JcaKeyFingerprintCalculator() );
Iterator rIt = pgpPub.getKeyRings();

while (rIt.hasNext()) {
   PGPPublicKeyRing kRing = (PGPPublicKeyRing) rIt.next();
   Iterator kIt = kRing.getPublicKeys();

   while (kIt.hasNext()) {
       PGPPublicKey k = (PGPPublicKey) kIt.next();

       if (k.isEncryptionKey()) {
           return k;
       }
   }
}

throw new IllegalArgumentException(
       "Can't find encryption key in key ring.");
}
 
開發者ID:AnonymOnline,項目名稱:saveOrganizer,代碼行數:24,代碼來源:KeyIO.java

示例3: getSecretKey

import org.bouncycastle.openpgp.PGPUtil; //導入方法依賴的package包/類
static PGPSecretKey getSecretKey(String privateKeyData) throws IOException, PGPException {
  PGPPrivateKey privKey = null;
  try (InputStream privStream = new ArmoredInputStream(new ByteArrayInputStream(privateKeyData.getBytes("UTF-8")))) {
    PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(PGPUtil.getDecoderStream(privStream), new JcaKeyFingerprintCalculator());
    Iterator keyRingIter = pgpSec.getKeyRings();
    while (keyRingIter.hasNext()) {
      PGPSecretKeyRing keyRing = (PGPSecretKeyRing)keyRingIter.next();
      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.");
}
 
開發者ID:quan-to,項目名稱:react-native-pgp,代碼行數:20,代碼來源:PGPUtils.java

示例4: readSecretKey

import org.bouncycastle.openpgp.PGPUtil; //導入方法依賴的package包/類
private PGPSecretKey readSecretKey() throws IOException, PGPException {
  PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(
      PGPUtil.getDecoderStream(new ByteArrayInputStream(config.keypair.getBytes())),
      new JcaKeyFingerprintCalculator());

  Iterator<PGPSecretKeyRing> keyRings = pgpSec.getKeyRings();
  while (keyRings.hasNext()) {
    PGPSecretKeyRing keyRing = (PGPSecretKeyRing) keyRings.next();

    Iterator<PGPSecretKey> keys = keyRing.getSecretKeys();
    while (keys.hasNext()) {
      PGPSecretKey key = (PGPSecretKey) keys.next();

      if (key.isSigningKey()) {
        return key;
      }
    }
  }

  throw new IllegalStateException("Can't find signing key in key ring.");
}
 
開發者ID:sonatype-nexus-community,項目名稱:nexus-repository-apt,代碼行數:22,代碼來源:AptSigningFacet.java

示例5: verify

import org.bouncycastle.openpgp.PGPUtil; //導入方法依賴的package包/類
/**
 * Verify a signature. Only return true if signature matches calculated signature of signedData
 * and if it was signed by the publicKey
 *
 * @param signedData
 * @param signature
 * @return
 */
public boolean verify(InputStream signedData, InputStream signature) {
    try {
        signature = PGPUtil.getDecoderStream(signature);
        JcaPGPObjectFactory pgpFact = new JcaPGPObjectFactory(signature);
        PGPSignature sig = ((PGPSignatureList) pgpFact.nextObject()).get(0);
        PGPPublicKey key = pgpPubRingCollection.getPublicKey(sig.getKeyID());
        sig.init(new JcaPGPContentVerifierBuilderProvider().setProvider("BC"), key);
        byte[] buff = new byte[1024];
        int read = 0;
        while ((read = signedData.read(buff)) != -1) {
            sig.update(buff, 0, read);
        }
        signedData.close();
        return sig.verify();
    }
    catch (Exception ex) {
        // can we put a logger here please?
        return false;
    }
}
 
開發者ID:atomist-attic,項目名稱:rug-resolver,代碼行數:29,代碼來源:GpgSignatureVerifier.java

示例6: getPublicKey

import org.bouncycastle.openpgp.PGPUtil; //導入方法依賴的package包/類
public PGPPublicKeyRing getPublicKey(final InputStream in) {
    Object obj;
    try {
        final PGPObjectFactory pgpFact = new PGPObjectFactory(
                PGPUtil.getDecoderStream(in));
        obj = pgpFact.nextObject();
    }
    catch (final Exception e) {
        throw new IllegalStateException(e);
    }

    if (obj instanceof PGPPublicKeyRing) {
        final PGPPublicKeyRing keyRing = (PGPPublicKeyRing) obj;
        rememberKey(keyRing);
        return keyRing;
    }

    throw new IllegalStateException("Pblic key not available");
}
 
開發者ID:gvSIGAssociation,項目名稱:gvnix1,代碼行數:20,代碼來源:PgpServiceImpl.java

示例7: readPublicKey

import org.bouncycastle.openpgp.PGPUtil; //導入方法依賴的package包/類
public static PGPPublicKey readPublicKey( InputStream is ) throws IOException, PGPException
{
    PGPPublicKeyRingCollection pgpPub =
            new PGPPublicKeyRingCollection( PGPUtil.getDecoderStream( is ), new JcaKeyFingerprintCalculator() );

    Iterator keyRingIter = pgpPub.getKeyRings();

    while ( keyRingIter.hasNext() )
    {
        PGPPublicKeyRing keyRing = ( PGPPublicKeyRing ) keyRingIter.next();
        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." );
}
 
開發者ID:subutai-io,項目名稱:base,代碼行數:26,代碼來源:PGPKeyHelper.java

示例8: readSecretKey

import org.bouncycastle.openpgp.PGPUtil; //導入方法依賴的package包/類
private static PGPSecretKey readSecretKey( InputStream is ) throws IOException, PGPException
{
    PGPSecretKeyRingCollection pgpSec =
            new PGPSecretKeyRingCollection( PGPUtil.getDecoderStream( is ), new JcaKeyFingerprintCalculator() );
    Iterator keyRingIter = pgpSec.getKeyRings();

    while ( keyRingIter.hasNext() )
    {
        PGPSecretKeyRing keyRing = ( PGPSecretKeyRing ) keyRingIter.next();
        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." );
}
 
開發者ID:subutai-io,項目名稱:base,代碼行數:25,代碼來源:PGPKeyHelper.java

示例9: extractSecrectKeyRings

import org.bouncycastle.openpgp.PGPUtil; //導入方法依賴的package包/類
private static List<PGPSecretKeyRing> extractSecrectKeyRings(InputStream inputStream) {

        InputStream decodedInput;
        try {
            decodedInput = PGPUtil.getDecoderStream(inputStream);
        } catch (final IOException e) {
            throw JkUtilsThrowable.unchecked(e);
        }
        final KeyFingerPrintCalculator fingerPrintCalculator = new JcaKeyFingerprintCalculator();
        final InnerPGPObjectFactory pgpFact = new InnerPGPObjectFactory(decodedInput,
                fingerPrintCalculator);
        PGPSecretKeyRing secKeyRing;
        final List<PGPSecretKeyRing> result = new LinkedList<>();
        while ((secKeyRing = pgpFact.nextSecretKey()) != null) {
            result.add(secKeyRing);
        }
        return result;
    }
 
開發者ID:jerkar,項目名稱:jerkar,代碼行數:19,代碼來源:PgpUtils.java

示例10: createKeyFrom

import org.bouncycastle.openpgp.PGPUtil; //導入方法依賴的package包/類
public PGPPublicKey createKeyFrom(InputStream in) throws IOException, PGPException {
	
	InputStream pgpData = PGPUtil.getDecoderStream(in);
	
	PGPPublicKeyRingCollection pgpPub = new PGPPublicKeyRingCollection(
			PGPUtil.getDecoderStream(pgpData), new JcaKeyFingerprintCalculator());

	Iterator keyRingIter = pgpPub.getKeyRings();
	while (keyRingIter.hasNext())
	{
		PGPPublicKeyRing keyRing = (PGPPublicKeyRing)keyRingIter.next();

		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.");
}
 
開發者ID:mpw96,項目名稱:geocaching,代碼行數:26,代碼來源:PublicKeyCreator.java

示例11: verifySignature

import org.bouncycastle.openpgp.PGPUtil; //導入方法依賴的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();
}
 
開發者ID:vert-x3,項目名稱:vertx-http-service-factory,代碼行數:29,代碼來源:PGPHelper.java

示例12: OpenPGPSecretKey

import org.bouncycastle.openpgp.PGPUtil; //導入方法依賴的package包/類
public OpenPGPSecretKey(String keyId, InputStream secretKeyRing, char[] password) throws IOException {
	PGPObjectFactory pgpObjectFactory = new BcPGPObjectFactory(PGPUtil.getDecoderStream(secretKeyRing));

	for (Object it = pgpObjectFactory.nextObject(); it != null; it = pgpObjectFactory.nextObject()) {
		PGPSecretKeyRing pgpSecretKeyRing = (PGPSecretKeyRing) it;
		PGPSecretKey pgpSecretKey = pgpSecretKeyRing.getSecretKey();

		if (keyId == null || keyId.isEmpty() || Long.valueOf(keyId, 16) == (pgpSecretKey.getKeyID() & MASK)) {
			this.secretKey = pgpSecretKey;
			break;
		}
	}

	// sanity check
	if (secretKey == null) {
		throw new IllegalArgumentException("Secret key " + keyId + " not found");
	}

	this.password = password;
}
 
開發者ID:rednoah,項目名稱:ant-spk,代碼行數:21,代碼來源:OpenPGPSecretKey.java

示例13: getKey

import org.bouncycastle.openpgp.PGPUtil; //導入方法依賴的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;
    }
 
開發者ID:s4u,項目名稱:pgpverify-maven-plugin,代碼行數:25,代碼來源:PGPKeysCache.java

示例14: readSignatureFile

import org.bouncycastle.openpgp.PGPUtil; //導入方法依賴的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);
	}
}
 
開發者ID:cloudstore,項目名稱:cloudstore,代碼行數:20,代碼來源:PGPVerifier.java

示例15: readPublicKey

import org.bouncycastle.openpgp.PGPUtil; //導入方法依賴的package包/類
protected static PGPPublicKey readPublicKey(InputStream in) throws IOException, PGPException {

        BcPGPPublicKeyRingCollection pgpPub = new BcPGPPublicKeyRingCollection(
                PGPUtil.getDecoderStream(in));
        in.close();

        Iterator<PGPPublicKeyRing> rIt = pgpPub.getKeyRings();
        while (rIt.hasNext()) {
            PGPPublicKeyRing kRing = rIt.next();
            Iterator<PGPPublicKey> kIt = kRing.getPublicKeys();

            while (kIt.hasNext()) {
                PGPPublicKey k = kIt.next();

                if (k.isEncryptionKey()) {
                    return k;
                }
            }
        }

        throw new IllegalArgumentException("Can't find encryption key in key ring.");
    }
 
開發者ID:jiucai,項目名稱:appframework,代碼行數:23,代碼來源:AbstractPGPEncryptor.java


注:本文中的org.bouncycastle.openpgp.PGPUtil.getDecoderStream方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。