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


Java PGPPublicKey类代码示例

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


PGPPublicKey类属于org.bouncycastle.openpgp包,在下文中一共展示了PGPPublicKey类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeData

import org.bouncycastle.openpgp.PGPPublicKey; //导入依赖的package包/类
public static void writeData(List<Calendar> data) throws Exception
{
	List<PGPPublicKey> pubKeys = new ArrayList<PGPPublicKey>();
	pubKeys.add(ppk);
	pubKeys.add(davidPub);
	try
	{
		if (!dataFile.exists())
			dataFile.createNewFile();
		DataXMLParser.writeData(dataFile, data, pubKeys);
	} catch (Exception e)
	{
		Main.logger.error("Error while writing data!", e);
		throw e;
	}
}
 
开发者ID:AnonymOnline,项目名称:saveOrganizer,代码行数:17,代码来源:Main.java

示例2: readPublicKey

import org.bouncycastle.openpgp.PGPPublicKey; //导入依赖的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: getKeyInfo

import org.bouncycastle.openpgp.PGPPublicKey; //导入依赖的package包/类
/**
 * Returns information on a public key
 * @param key A PGP public key
 * @return Key information
 */
public static String getKeyInfo(PGPPublicKey key) {
    
    StringBuffer info = new StringBuffer(PGPInit.getKeyExchangeAlgorithm(key.getAlgorithm()))
        .append(" (").append(key.getBitStrength()).append(")")
        .append(" v").append(key.getVersion())
        .append(" id:").append(key.getKeyID())
        .append(" ").append(key.getCreationTime());
    if (key.isEncryptionKey()) {
        info.append(" [").append("encryption").append("]");
    }
    if (key.isMasterKey()) {
        info.append(" [").append("master").append("]");
    }
    if (key.isRevoked()) {
        info.append(" [").append("revoked").append("]");
    }
    
    return info.toString();
}
 
开发者ID:SoftwareAG,项目名称:webmethods-integrationserver-pgpencryption,代码行数:25,代码来源:PGPKeyReader.java

示例4: verify

import org.bouncycastle.openpgp.PGPPublicKey; //导入依赖的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

示例5: findPublicKey

import org.bouncycastle.openpgp.PGPPublicKey; //导入依赖的package包/类
@Deprecated
public static PGPPublicKey findPublicKey(CamelContext context, String filename, byte[] keyRing, String userid, boolean forEncryption)
    throws IOException, PGPException, NoSuchProviderException {

    InputStream is = determineKeyRingInputStream(context, filename, keyRing, forEncryption);

    try {
        List<PGPPublicKey> result = findPublicKeys(is, Collections.singletonList(userid), forEncryption);
        if (result.isEmpty()) {
            return null;
        } else {
            return result.get(0);
        }
    } finally {
        IOHelper.close(is);
    }

}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:PGPDataFormatUtil.java

示例6: test11

import org.bouncycastle.openpgp.PGPPublicKey; //导入依赖的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");
        }
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:17,代码来源:BcPGPKeyRingTest.java

示例7: testEncryptOnly

import org.bouncycastle.openpgp.PGPPublicKey; //导入依赖的package包/类
@Theory
public void testEncryptOnly(Content content) throws Exception {
  Keyring keyring = new FakeKeyringModule().get();
  byte[] data = content.get().getBytes(UTF_8);
  PGPPublicKey publicKey = keyring.getRdeStagingEncryptionKey();
  PGPPrivateKey privateKey = keyring.getRdeStagingDecryptionKey();

  Ghostryde ghost = new Ghostryde(1024);
  ByteArrayOutputStream bsOut = new ByteArrayOutputStream();
  try (Ghostryde.Encryptor encryptor = ghost.openEncryptor(bsOut, publicKey)) {
    encryptor.write(data);
  }

  ByteArrayInputStream bsIn = new ByteArrayInputStream(bsOut.toByteArray());
  bsOut.reset();
  try (Ghostryde.Decryptor decryptor = ghost.openDecryptor(bsIn, privateKey)) {
    ByteStreams.copy(decryptor, bsOut);
  }

  assertThat(new String(bsOut.toByteArray(), UTF_8)).isEqualTo(content.get());
}
 
开发者ID:google,项目名称:nomulus,代码行数:22,代码来源:GhostrydeTest.java

示例8: getPublicKeyWithKeyIdAndUserID

import org.bouncycastle.openpgp.PGPPublicKey; //导入依赖的package包/类
/**
 * Determines a public key from the keyring collection which has a certain
 * key ID and which has a User ID which contains at least one of the User ID
 * parts.
 * 
 * @param keyId
 *            key ID
 * @param userIdParts
 *            user ID parts, can be empty, than no filter on the User ID is
 *            executed
 * @param publicKeyringCollection
 *            keyring collection
 * @return public key or <code>null</code> if no fitting key is found
 * @throws PGPException
 */
@SuppressWarnings("unchecked")
public static PGPPublicKey getPublicKeyWithKeyIdAndUserID(long keyId, List<String> userIdParts, PGPPublicKeyRingCollection publicKeyringCollection)
    throws PGPException {
    PGPPublicKeyRing publicKeyring = publicKeyringCollection.getPublicKeyRing(keyId);
    if (publicKeyring == null) {
        LOG.debug("No public key found for key ID {}.", Long.toString(keyId));
        return null;
    }
    // publicKey can be a subkey the user IDs must therefore be provided by the primary/master key
    if (isAllowedKey(userIdParts, publicKeyring.getPublicKey().getUserIDs())) {
        return publicKeyring.getPublicKey(keyId);
    } else {
        return null;
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:31,代码来源:PGPDataFormatUtil.java

示例9: setApprovedResult

import org.bouncycastle.openpgp.PGPPublicKey; //导入依赖的package包/类
private void setApprovedResult( final RegistrationData result, final String keyPhrase )
{
    String sslCert =
            securityManager.getKeyStoreManager().exportCertificate( Common.DEFAULT_PUBLIC_SECURE_PORT, "" );

    PGPPublicKey pkey = securityManager.getKeyManager().getPublicKey( localPeerId );
    try
    {
        byte[] key = SecurityUtilities.generateKey( keyPhrase.getBytes( "UTF-8" ) );
        Encrypted encryptedSslCert = new Encrypted( sslCert, key );
        result.setSslCert( encryptedSslCert );
        String publicKey = PGPKeyUtil.exportAscii( pkey );
        Encrypted encryptedPublicKey = new Encrypted( publicKey, key );
        result.setPublicKey( encryptedPublicKey );
    }
    catch ( Exception e )
    {
        LOG.warn( e.getMessage(), e );
    }
}
 
开发者ID:subutai-io,项目名称:base,代码行数:21,代码来源:PeerManagerImpl.java

示例10: verifyPublicKey

import org.bouncycastle.openpgp.PGPPublicKey; //导入依赖的package包/类
/**
 * Verifies that a public key is signed with another public key
 *
 * @param keyToVerify the public key to verify
 * @param id the id we are verifying against the public key
 * @param keyToVerifyWith the key to verify with
 *
 * @return true if verified, false otherwise
 */
public static boolean verifyPublicKey( PGPPublicKey keyToVerify, String id, PGPPublicKey keyToVerifyWith )
        throws PGPException
{
    try
    {
        Iterator<PGPSignature> signIterator = keyToVerify.getSignatures();
        while ( signIterator.hasNext() )
        {
            PGPSignature signature = signIterator.next();
            signature.init( new JcaPGPContentVerifierBuilderProvider().setProvider( provider ), keyToVerifyWith );
            if ( signature.verifyCertification( id.getBytes(), keyToVerify ) )
            {
                return true;
            }
        }
        return false;
    }
    catch ( Exception e )
    {
        //throw custom  exception
        throw new PGPException( "Error verifying public key", e );
    }
}
 
开发者ID:subutai-io,项目名称:base,代码行数:33,代码来源:PGPEncryptionUtil.java

示例11: removeSignature

import org.bouncycastle.openpgp.PGPPublicKey; //导入依赖的package包/类
public static PGPPublicKeyRing removeSignature( PGPPublicKeyRing keyToRemoveFrom, String id ) throws PGPException
{
    try
    {
        PGPPublicKey oldKey = keyToRemoveFrom.getPublicKey();
        PGPPublicKey newKey = PGPPublicKey.removeCertification( oldKey, id );

        PGPPublicKeyRing newPublicKeyRing = PGPPublicKeyRing.removePublicKey( keyToRemoveFrom, oldKey );
        return PGPPublicKeyRing.insertPublicKey( newPublicKeyRing, newKey );
    }
    catch ( Exception e )
    {
        //throw custom  exception
        throw new PGPException( "Error removing signature", e );
    }
}
 
开发者ID:subutai-io,项目名称:base,代码行数:17,代码来源:PGPEncryptionUtil.java

示例12: testSignEncryptAndDecryptVerify

import org.bouncycastle.openpgp.PGPPublicKey; //导入依赖的package包/类
@Test
public void testSignEncryptAndDecryptVerify() throws Exception
{
    PGPSecretKey signingKey =
            PGPEncryptionUtil.findSecretKeyByFingerprint( findFile( SECRET_KEYRING ), SECRET_KEY_FINGERPRINT );
    PGPPublicKey encryptingKey =
            PGPEncryptionUtil.findPublicKeyByFingerprint( findFile( PUBLIC_KEYRING ), PUBLIC_KEY_FINGERPRINT );

    byte[] signedAndEncryptedMessage =
            PGPEncryptionUtil.signAndEncrypt( MESSAGE.getBytes(), signingKey, SECRET_PWD, encryptingKey, true );

    PGPSecretKey decryptingSecretKey = PGPEncryptionUtil.findSecretKeyByFingerprint( findFile( SECRET_KEYRING ),
            PGPEncryptionUtil.BytesToHex( encryptingKey.getFingerprint() ) );

    byte[] decryptedAndVerifiedMessage = PGPEncryptionUtil
            .decryptAndVerify( signedAndEncryptedMessage, decryptingSecretKey, SECRET_PWD,
                    signingKey.getPublicKey() );

    assertTrue( Arrays.equals( MESSAGE.getBytes(), decryptedAndVerifiedMessage ) );
}
 
开发者ID:subutai-io,项目名称:base,代码行数:21,代码来源:PGPEncryptionUtilTest.java

示例13: testGetX509CertificateFromPgpKeyPair

import org.bouncycastle.openpgp.PGPPublicKey; //导入依赖的package包/类
@Test
public void testGetX509CertificateFromPgpKeyPair() throws Exception
{

    Date today = new Date();
    PGPPublicKey pgpPublicKey = PGPEncryptionUtil.findPublicKeyById( findFile( PUBLIC_KEYRING ), PUBLIC_KEY_ID );
    PGPSecretKey pgpSecretKey = PGPEncryptionUtil.findSecretKeyById( findFile( SECRET_KEYRING ), SECRET_KEY_ID );
    X509Certificate x509Certificate = PGPEncryptionUtil
            .getX509CertificateFromPgpKeyPair( pgpPublicKey, pgpSecretKey, SECRET_PWD,
                    "C=ZA, ST=Western Cape, L=Cape Town, O=Thawte Consulting cc,"
                            + " OU=Certification Services Division,"
                            + " CN=Thawte Server CA/[email protected]",
                    "C=US, ST=Maryland, L=Pasadena, O=Brent Baccala,"
                            + "OU=FreeSoft, CN=www.freesoft.org/[email protected]",

                    today, new Date( today.getTime() + ( 1000 * 60 * 60 * 24 ) ), new BigInteger( "1" ) );

    assertNotNull( x509Certificate );


    JcaPGPKeyConverter c = new JcaPGPKeyConverter();
    PublicKey publicKey = c.getPublicKey( pgpSecretKey.getPublicKey() );
    x509Certificate.verify( publicKey, new BouncyCastleProvider() );
}
 
开发者ID:subutai-io,项目名称:base,代码行数:25,代码来源:PGPEncryptionUtilTest.java

示例14: readPublicKey

import org.bouncycastle.openpgp.PGPPublicKey; //导入依赖的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

示例15: rememberKey

import org.bouncycastle.openpgp.PGPPublicKey; //导入依赖的package包/类
/**
 * Simply stores the key ID in {@link #discoveredKeyIds} for future
 * reference of all Key IDs we've come across. This method uses a
 * {@link PGPPublicKeyRing} to ensure the input is actually a valid key,
 * plus locating any key IDs that have signed the key.
 * <p>
 * Please note {@link #discoveredKeyIds} is not used for any key functions
 * of this class. It is simply for user interface convenience.
 * 
 * @param keyRing the key ID to store (required)
 */
@SuppressWarnings("unchecked")
private void rememberKey(final PGPPublicKeyRing keyRing) {
    final PGPPublicKey key = keyRing.getPublicKey();
    if (key != null) {
        final PgpKeyId keyId = new PgpKeyId(key);
        discoveredKeyIds.add(keyId);
        final Iterator<String> userIdIterator = key.getUserIDs();
        while (userIdIterator.hasNext()) {
            final String userId = userIdIterator.next();
            final Iterator<PGPSignature> signatureIterator = key
                    .getSignaturesForID(userId);
            while (signatureIterator.hasNext()) {
                final PGPSignature signature = signatureIterator.next();
                final PgpKeyId signatureKeyId = new PgpKeyId(signature);
                discoveredKeyIds.add(signatureKeyId);
            }
        }
    }
}
 
开发者ID:gvSIGAssociation,项目名称:gvnix1,代码行数:31,代码来源:PgpServiceImpl.java


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