当前位置: 首页>>代码示例>>Java>>正文


Java PGPUtil类代码示例

本文整理汇总了Java中org.bouncycastle.openpgp.PGPUtil的典型用法代码示例。如果您正苦于以下问题:Java PGPUtil类的具体用法?Java PGPUtil怎么用?Java PGPUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PGPUtil类属于org.bouncycastle.openpgp包,在下文中一共展示了PGPUtil类的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: getEncryptedObjects

import org.bouncycastle.openpgp.PGPUtil; //导入依赖的package包/类
@SuppressWarnings( "unchecked" )
private static Iterator<PGPPublicKeyEncryptedData> getEncryptedObjects( final byte[] message ) throws IOException
{
    try
    {
        final PGPObjectFactory factory =
                new PGPObjectFactory( PGPUtil.getDecoderStream( new ByteArrayInputStream( message ) ),
                        new JcaKeyFingerprintCalculator() );
        final Object first = factory.nextObject();
        final Object list = ( first instanceof PGPEncryptedDataList ) ? first : factory.nextObject();
        return ( ( PGPEncryptedDataList ) list ).getEncryptedDataObjects();
    }
    catch ( IOException e )
    {
        throw new IOException( e );
    }
}
 
开发者ID:subutai-io,项目名称:base,代码行数:18,代码来源:PGPEncryptionUtil.java

示例3: readSecretKey

import org.bouncycastle.openpgp.PGPUtil; //导入依赖的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.");
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:PGPDataFormatTest.java

示例4: 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

示例5: 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

示例6: 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

示例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: getKey

import org.bouncycastle.openpgp.PGPUtil; //导入依赖的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;
    }
 
开发者ID:netmackan,项目名称:java-binrepo-proxy,代码行数:25,代码来源:PGPKeysCache.java

示例10: 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

示例11: signExternal

import org.bouncycastle.openpgp.PGPUtil; //导入依赖的package包/类
public byte[] signExternal(String input) throws IOException, PGPException {
  PGPSecretKey signKey = readSecretKey();
  PGPPrivateKey privKey = signKey.extractPrivateKey(
      new JcePBESecretKeyDecryptorBuilder().setProvider("BC").build(config.passphrase.toCharArray()));
  PGPSignatureGenerator sigGenerator = new PGPSignatureGenerator(
      new JcaPGPContentSignerBuilder(signKey.getPublicKey().getAlgorithm(), PGPUtil.SHA256).setProvider("BC"));
  sigGenerator.init(PGPSignature.BINARY_DOCUMENT, privKey);

  ByteArrayOutputStream buffer = new ByteArrayOutputStream();

  try (ArmoredOutputStream aOut = new ArmoredOutputStream(buffer)) {
    BCPGOutputStream bOut = new BCPGOutputStream(aOut);
    sigGenerator.update(input.getBytes(Charsets.UTF_8));
    sigGenerator.generate().encode(bOut);
  }

  return buffer.toByteArray();
}
 
开发者ID:sonatype-nexus-community,项目名称:nexus-repository-apt,代码行数:19,代码来源:AptSigningFacet.java

示例12: 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

示例13: readPublicKey

import org.bouncycastle.openpgp.PGPUtil; //导入依赖的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.");
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:PGPDataFormatTest.java

示例14: 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

示例15: 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


注:本文中的org.bouncycastle.openpgp.PGPUtil类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。