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


Java PGPSecretKey.extractPrivateKey方法代码示例

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


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

示例1: getPrivateKey

import org.bouncycastle.openpgp.PGPSecretKey; //导入方法依赖的package包/类
/**
 * ***********************************************
 */
public static PGPPrivateKey getPrivateKey( final PGPSecretKey secretKey, final String secretPwd )
{
    Preconditions.checkNotNull( secretKey );
    Preconditions.checkNotNull( secretPwd );

    try
    {
        return secretKey.extractPrivateKey(
                new JcePBESecretKeyDecryptorBuilder().setProvider( provider ).build( secretPwd.toCharArray() ) );
    }
    catch ( Exception e )
    {
        LOG.error( "Unable to extract key {}: {}", secretKey.getKeyID(), e.getMessage() );
    }

    return null;
}
 
开发者ID:subutai-io,项目名称:base,代码行数:21,代码来源:PGPEncryptionUtil.java

示例2: lookupKeyPair

import org.bouncycastle.openpgp.PGPSecretKey; //导入方法依赖的package包/类
/**
 * Same as {@link #lookupPublicKey} but also retrieves the associated private key.
 *
 * @throws VerifyException if either keys couldn't be found.
 * @see #lookupPublicKey
 */
@SuppressWarnings("deprecation")
public static PGPKeyPair lookupKeyPair(
    PGPPublicKeyRingCollection publics,
    PGPSecretKeyRingCollection privates,
    String query,
    KeyRequirement want) {
  PGPPublicKey publicKey = lookupPublicKey(publics, query, want);
  PGPPrivateKey privateKey;
  try {
    PGPSecretKey secret = verifyNotNull(privates.getSecretKey(publicKey.getKeyID()),
        "Keyring missing private key associated with public key id: %x (query '%s')",
        publicKey.getKeyID(), query);
    // We do not support putting a password on the private key so we're just going to
    // put char[0] here.
    privateKey = secret.extractPrivateKey(
        new BcPBESecretKeyDecryptorBuilder(new BcPGPDigestCalculatorProvider())
            .build(new char[0]));
  } catch (PGPException e) {
    throw new VerifyException(e.getMessage());
  }
  return new PGPKeyPair(publicKey, privateKey);
}
 
开发者ID:google,项目名称:nomulus,代码行数:29,代码来源:PgpHelper.java

示例3: signExternal

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

示例4: createSignature

import org.bouncycastle.openpgp.PGPSecretKey; //导入方法依赖的package包/类
private void createSignature(OutputStream out) throws Exception {
    PGPSecretKey pgpSec = readSecretKey();
    PGPPrivateKey pgpPrivKey = pgpSec.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider(getProvider()).build(
            "sdude".toCharArray()));
    PGPSignatureGenerator sGen = new PGPSignatureGenerator(new JcaPGPContentSignerBuilder(pgpSec.getPublicKey().getAlgorithm(),
            HashAlgorithmTags.SHA1).setProvider(getProvider()));

    sGen.init(PGPSignature.BINARY_DOCUMENT, pgpPrivKey);

    BCPGOutputStream bOut = new BCPGOutputStream(out);

    InputStream fIn = new ByteArrayInputStream("Test Signature".getBytes("UTF-8"));

    int ch;
    while ((ch = fIn.read()) >= 0) {
        sGen.update((byte) ch);
    }

    fIn.close();

    sGen.generate().encode(bOut);

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

示例5: extractPrivateKey

import org.bouncycastle.openpgp.PGPSecretKey; //导入方法依赖的package包/类
private static PGPPrivateKey extractPrivateKey(PGPSecretKey pgpSecKey, char[] passPhrase)
        throws PGPException {
    PGPPrivateKey privateKey = null;
    BcPGPDigestCalculatorProvider calculatorProvider = new BcPGPDigestCalculatorProvider();
    BcPBESecretKeyDecryptorBuilder secretKeyDecryptorBuilder = new BcPBESecretKeyDecryptorBuilder(
            calculatorProvider);
    PBESecretKeyDecryptor pBESecretKeyDecryptor = secretKeyDecryptorBuilder.build(passPhrase);

    try {
        privateKey = pgpSecKey.extractPrivateKey(pBESecretKeyDecryptor);
    } catch (PGPException e) {
        throw new PGPException("invalid privateKey passPhrase: " + String.valueOf(passPhrase),
                e);
    }

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

示例6: createPrivateKey

import org.bouncycastle.openpgp.PGPSecretKey; //导入方法依赖的package包/类
private PGPPrivateKey createPrivateKey(PGPSecretKey secretKey, String password) {
    try {
        PBESecretKeyDecryptor decryptor = new BcPBESecretKeyDecryptorBuilder(new BcPGPDigestCalculatorProvider()).build(password.toCharArray());
        return secretKey.extractPrivateKey(decryptor);
    } catch (PGPException e) {
        throw new UncheckedException(e);
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:9,代码来源:PgpSignatory.java

示例7: readPrivateKey

import org.bouncycastle.openpgp.PGPSecretKey; //导入方法依赖的package包/类
public static PGPPrivateKey readPrivateKey(PGPSecretKey secret, char[] pass)
        throws PGPException, NoSuchProviderException {

    PGPPrivateKey key = null;
    try {
        key = secret.extractPrivateKey(pass, PGPInit.PROVIDER.getName());
    } catch (PGPException pgpe) {
        if (pgpe.getMessage().indexOf("checksum mismatch") >= 0) {
            throw new PGPException("Private key password invalid");
        } else {
            throw pgpe;
        }
    }
    return key;
}
 
开发者ID:SoftwareAG,项目名称:webmethods-integrationserver-pgpencryption,代码行数:16,代码来源:PGPKeyReader.java

示例8: rewrapTest

import org.bouncycastle.openpgp.PGPSecretKey; //导入方法依赖的package包/类
private void rewrapTest()
    throws Exception
{
    SecureRandom rand = new SecureRandom();

    // Read the secret key rings
    PGPSecretKeyRingCollection privRings = new PGPSecretKeyRingCollection(
                                                     new ByteArrayInputStream(rewrapKey), new BcKeyFingerprintCalculator());

    Iterator rIt = privRings.getKeyRings();

    if (rIt.hasNext())
    {
        PGPSecretKeyRing pgpPriv = (PGPSecretKeyRing)rIt.next();

        Iterator it = pgpPriv.getSecretKeys();

        while (it.hasNext())
        {
            PGPSecretKey pgpKey = (PGPSecretKey)it.next();

            // re-encrypt the key with an empty password
            pgpPriv = PGPSecretKeyRing.removeSecretKey(pgpPriv, pgpKey);
            pgpKey = PGPSecretKey.copyWithNewPassword(
                                pgpKey,
                                new BcPBESecretKeyDecryptorBuilder(new BcPGPDigestCalculatorProvider()).build(rewrapPass),
                                null);
            pgpPriv = PGPSecretKeyRing.insertSecretKey(pgpPriv, pgpKey);
        
            // this should succeed
            PGPPrivateKey privTmp = pgpKey.extractPrivateKey(null);
        }
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:35,代码来源:BcPGPKeyRingTest.java

示例9: signPublicKey

import org.bouncycastle.openpgp.PGPSecretKey; //导入方法依赖的package包/类
/**
 * Signs a public key
 *
 * @param publicKeyRing a public key ring containing the single public key to sign
 * @param id the id we are certifying against the public key
 * @param secretKey the signing key
 * @param secretKeyPassword the signing key password
 *
 * @return a public key ring with the signed public key
 */
public static PGPPublicKeyRing signPublicKey( PGPPublicKeyRing publicKeyRing, String id, PGPSecretKey secretKey,
                                              String secretKeyPassword ) throws PGPException
{
    try
    {
        PGPPublicKey oldKey = publicKeyRing.getPublicKey();

        PGPPrivateKey pgpPrivKey = secretKey.extractPrivateKey(
                new JcePBESecretKeyDecryptorBuilder().setProvider( provider )
                                                     .build( secretKeyPassword.toCharArray() ) );

        PGPSignatureGenerator signatureGenerator = new PGPSignatureGenerator(
                new JcaPGPContentSignerBuilder( secretKey.getPublicKey().getAlgorithm(), PGPUtil.SHA1 ) );

        signatureGenerator.init( PGPSignature.DEFAULT_CERTIFICATION, pgpPrivKey );

        PGPSignature signature = signatureGenerator.generateCertification( id, oldKey );

        PGPPublicKey newKey = PGPPublicKey.addCertification( oldKey, signature );

        PGPPublicKeyRing newPublicKeyRing = PGPPublicKeyRing.removePublicKey( publicKeyRing, oldKey );

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

示例10: readPrivateKey

import org.bouncycastle.openpgp.PGPSecretKey; //导入方法依赖的package包/类
public static PGPPrivateKey readPrivateKey( InputStream is, String password ) throws PGPException, IOException
{
    PGPSecretKey secretKey = readSecretKey( is );

    return secretKey.extractPrivateKey(
            new JcePBESecretKeyDecryptorBuilder().setProvider( "BC" ).build( password.toCharArray() ) );
}
 
开发者ID:subutai-io,项目名称:base,代码行数:8,代码来源:PGPKeyHelper.java

示例11: findPrivateKey

import org.bouncycastle.openpgp.PGPSecretKey; //导入方法依赖的package包/类
/**
 * Get private key using the given passphrase
 * @param pgpSecKey The secret key
 * @param pass passphrase to decrypt secret key with
 * @return Private key
 * @throws PGPException
 */
private PGPPrivateKey findPrivateKey(PGPSecretKey pgpSecKey, char[] pass)
	throws PGPException {
	if (pgpSecKey == null) return null;

    PBESecretKeyDecryptor decryptor = new BcPBESecretKeyDecryptorBuilder(new BcPGPDigestCalculatorProvider()).build(pass);
    return pgpSecKey.extractPrivateKey(decryptor);
}
 
开发者ID:ibm-messaging,项目名称:mq-mft,代码行数:15,代码来源:CryptDecryptUtil.java

示例12: deserializeKeyPair

import org.bouncycastle.openpgp.PGPSecretKey; //导入方法依赖的package包/类
/** Deserialize a PGPKeyPair */
public static PGPKeyPair deserializeKeyPair(byte[] serialized)
    throws IOException, PGPException {
  PGPSecretKey secretKey =
      new BcPGPSecretKeyRing(
          PGPUtil.getDecoderStream(
              new ByteArrayInputStream(serialized))).getSecretKey();
  return new PGPKeyPair(
      secretKey.getPublicKey(),
      secretKey.extractPrivateKey(createSecretKeyDecryptor()));
}
 
开发者ID:google,项目名称:nomulus,代码行数:12,代码来源:KeySerializer.java

示例13: getKeyPair

import org.bouncycastle.openpgp.PGPSecretKey; //导入方法依赖的package包/类
static PGPKeyPair getKeyPair() throws Exception {
  PGPSecretKey secretKey = getPrivateKeyring().getSecretKey();
  return new PGPKeyPair(
      secretKey.getPublicKey(),
      secretKey.extractPrivateKey(
          new BcPBESecretKeyDecryptorBuilder(new BcPGPDigestCalculatorProvider())
          .build(new char[0])));
}
 
开发者ID:google,项目名称:nomulus,代码行数:9,代码来源:KmsTestHelper.java

示例14: extractPrivateKey

import org.bouncycastle.openpgp.PGPSecretKey; //导入方法依赖的package包/类
private static PGPPrivateKey extractPrivateKey(PGPSecretKey secretKey, String password) {
  try {
    return secretKey.extractPrivateKey(
        new BcPBESecretKeyDecryptorBuilder(new BcPGPDigestCalculatorProvider())
            .build(password.toCharArray()));
  } catch (PGPException e) {
    throw new Error(e);
  }
}
 
开发者ID:google,项目名称:nomulus,代码行数:10,代码来源:KeySerializerTest.java

示例15: signInline

import org.bouncycastle.openpgp.PGPSecretKey; //导入方法依赖的package包/类
public byte[] signInline(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.CANONICAL_TEXT_DOCUMENT, privKey);

  @SuppressWarnings("unchecked")
  Iterator<String> userIds = signKey.getUserIDs();
  if (userIds.hasNext()) {
    PGPSignatureSubpacketGenerator sigSubpacketGenerator = new PGPSignatureSubpacketGenerator();
    sigSubpacketGenerator.setSignerUserID(false, userIds.next());
    sigGenerator.setHashedSubpackets(sigSubpacketGenerator.generate());
  }

  String[] lines = input.split("\r?\n");
  ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  try (ArmoredOutputStream aOut = new ArmoredOutputStream(buffer)) {
    aOut.beginClearText(PGPUtil.SHA256);

    boolean firstLine = true;
    for (String line : lines) {
      String sigLine = (firstLine ? "" : "\r\n") + line.replaceAll("\\s*$", "");
      sigGenerator.update(sigLine.getBytes(Charsets.UTF_8));
      aOut.write((line + "\n").getBytes(Charsets.UTF_8));
      firstLine = false;
    }
    aOut.endClearText();

    BCPGOutputStream bOut = new BCPGOutputStream(aOut);
    sigGenerator.generate().encode(bOut);
  }
  return buffer.toByteArray();
}
 
开发者ID:sonatype-nexus-community,项目名称:nexus-repository-apt,代码行数:36,代码来源:AptSigningFacet.java


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