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


Java PGPSecretKeyRingCollection.getSecretKey方法代码示例

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


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

示例1: getPrivateKey

import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; //导入方法依赖的package包/类
/**
 * ***********************************************
 */
private static PGPPrivateKey getPrivateKey( final PGPSecretKeyRingCollection keys, final long id,
                                            final String secretPwd )
{
    try
    {
        final PGPSecretKey key = keys.getSecretKey( id );
        if ( key != null )
        {
            return key.extractPrivateKey( new JcePBESecretKeyDecryptorBuilder().setProvider( provider )
                                                                               .build( secretPwd.toCharArray() ) );
        }
    }
    catch ( final Exception e )
    {
        // Don't print the passphrase but do print null if thats what it was
        final String passphraseMessage = ( secretPwd == null ) ? "null" : "supplied";
        LOG.warn( "Unable to extract key " + id + " using " + passphraseMessage + " passphrase: {}",
                e.getMessage() );
    }
    return null;
}
 
开发者ID:subutai-io,项目名称:base,代码行数:25,代码来源:PGPEncryptionUtil.java

示例2: findSecretKey

import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; //导入方法依赖的package包/类
/**
 * Search a secret key ring collection for a secret key corresponding to keyID if it
 * exists.
 * 
 * @param pgpSec a secret key ring collection.
 * @param keyID keyID we want.
 * @param pass passphrase to decrypt secret key with.
 * @return
 * @throws PGPException
 * @throws NoSuchProviderException
 */
static PGPPrivateKey findSecretKey(PGPSecretKeyRingCollection pgpSec, long keyID, char[] pass)
    throws PGPException, NoSuchProviderException
{
    PGPSecretKey pgpSecKey = pgpSec.getSecretKey(keyID);

    if (pgpSecKey == null)
    {
        return null;
    }

    return pgpSecKey.extractPrivateKey(pass, "BC");
}
 
开发者ID:petrsmid,项目名称:unicredit-connector,代码行数:24,代码来源:BouncyCastlePGPExampleUtil.java

示例3: decrypt

import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; //导入方法依赖的package包/类
public static final byte[] decrypt(File privring, long keyid, char[] pw, byte[] in){
	if(!privring.exists() || !privring.isFile()) return null;
	
	try {
		byte[] ret = null;
		
		FileInputStream fis = new FileInputStream(privring);
		InputStream is = PGPUtil.getDecoderStream(fis);
		PGPSecretKeyRingCollection ring = new PGPSecretKeyRingCollection(is);
        PGPSecretKey seckey = ring.getSecretKey(keyid);
		if(seckey.isMasterKey()) {
			System.err.println("Someone tried to use a non-encryption key. This should never happen.");
			return null;
		}
		
        PrivateKey key = new JcaPGPKeyConverter().getPrivateKey(
        					seckey.extractPrivateKey(
        						new JcePBESecretKeyDecryptorBuilder().setProvider("BC").build(pw)
        					)
           				);
        
	    Cipher cipher = Cipher.getInstance(key.getAlgorithm() + "/ECB/PKCS1Padding");
	    cipher.init(Cipher.DECRYPT_MODE, key);
	    ret = cipher.doFinal(in);
        
        is.close();
        fis.close();
		
		return ret;
	} catch (Exception e) {
		System.err.println(e.getLocalizedMessage());
		return null;
	}
}
 
开发者ID:fhissen,项目名称:CrococryptFile,代码行数:35,代码来源:PGPUtils.java

示例4: findSecretKey

import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; //导入方法依赖的package包/类
private static PGPPrivateKey findSecretKey(
        PGPSecretKeyRingCollection pgpSec, long keyID, char[] pass)
        throws PGPException, NoSuchProviderException {
    PGPSecretKey pgpSecKey = pgpSec.getSecretKey(keyID);

    if (pgpSecKey == null) {
        return null;
    }

    final PBESecretKeyDecryptor decryptor = new BcPBESecretKeyDecryptorBuilder(
            new BcPGPDigestCalculatorProvider()).build(pass);
    return pgpSecKey.extractPrivateKey(decryptor);
}
 
开发者ID:payneteasy,项目名称:superfly,代码行数:14,代码来源:PGPUtils.java

示例5: findSecretKey

import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; //导入方法依赖的package包/类
public static PGPPrivateKey findSecretKey(final InputStream keyIn, final long keyID, final char[] pass) throws IOException, PGPException {
    final PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(PGPUtil.getDecoderStream(keyIn), new BcKeyFingerprintCalculator());
    final PGPSecretKey pgpSecKey = pgpSec.getSecretKey(keyID);
    if (pgpSecKey == null) return null;

    final PBESecretKeyDecryptor decryptor = new BcPBESecretKeyDecryptorBuilder(new BcPGPDigestCalculatorProvider()).build(pass);
    return pgpSecKey.extractPrivateKey(decryptor);
}
 
开发者ID:subshare,项目名称:subshare,代码行数:9,代码来源:GnuPgTest.java

示例6: findSecretKey

import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; //导入方法依赖的package包/类
/**
 * Private util function that finds the private key from keyring collection based on keyId and passPhrase
 * @param pgpSec keyring collection
 * @param keyID keyID for this encryption file
 * @param passPhrase passPhrase for this encryption file
 * @throws PGPException
 */
private PGPPrivateKey findSecretKey(PGPSecretKeyRingCollection pgpSec, long keyID, String passPhrase)
    throws PGPException {

  PGPSecretKey pgpSecKey = pgpSec.getSecretKey(keyID);
  if (pgpSecKey == null) {
    return null;
  }
  return pgpSecKey.extractPrivateKey(
      new JcePBESecretKeyDecryptorBuilder()
          .setProvider(BouncyCastleProvider.PROVIDER_NAME).build(passPhrase.toCharArray()));
}
 
开发者ID:apache,项目名称:incubator-gobblin,代码行数:19,代码来源:GPGFileDecryptor.java

示例7: findSecretKey

import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; //导入方法依赖的package包/类
/**
 * Search a secret key ring collection for a secret key corresponding to keyID if it
 * exists.
 * 
 * @param pgpSec a secret key ring collection.
 * @param keyID keyID we want.
 * @param pass passphrase to decrypt secret key with.
 * @return the private key.
 * @throws PGPException
 * @throws NoSuchProviderException
 */
static PGPPrivateKey findSecretKey(PGPSecretKeyRingCollection pgpSec, long keyID, char[] pass)
    throws PGPException, NoSuchProviderException
{
    PGPSecretKey pgpSecKey = pgpSec.getSecretKey(keyID);

    if (pgpSecKey == null)
    {
        return null;
    }

    return pgpSecKey.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider("BC").build(pass));
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:24,代码来源:PGPExampleUtil.java

示例8: findSecretKey

import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; //导入方法依赖的package包/类
protected static PGPPrivateKey findSecretKey(PGPSecretKeyRingCollection pgpSec, long keyID,
        char[] pass) throws PGPException, NoSuchProviderException {
    PGPPrivateKey privateKey = null;
    PGPSecretKey pgpSecKey = pgpSec.getSecretKey(keyID);

    if (pgpSecKey == null) {
        return null;
    }
    privateKey = extractPrivateKey(pgpSecKey, pass);

    return privateKey;
}
 
开发者ID:jiucai,项目名称:appframework,代码行数:13,代码来源:PGPDecryptor.java

示例9: findSecretKey

import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; //导入方法依赖的package包/类
/**
 * Search a secret key ring collection for a secret key corresponding to
 * keyID if it exists.
 * 
 * @param pgpSec
 *            a secret key ring collection.
 * @param keyID
 *            keyID we want.
 * @param pass
 *            passphrase to decrypt secret key with.
 * @return the private key.
 * @throws PGPException
 * @throws NoSuchProviderException
 */
static PGPPrivateKey findSecretKey(PGPSecretKeyRingCollection pgpSec, long keyID, char[] pass)
		throws PGPException, NoSuchProviderException
{
	PGPSecretKey pgpSecKey = pgpSec.getSecretKey(keyID);

	if (pgpSecKey == null)
	{
		return null;
	}

	return pgpSecKey.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider("BC").build(pass));
}
 
开发者ID:AnonymOnline,项目名称:saveOrganizer,代码行数:27,代码来源:PGPUtils.java


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