當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。