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


Java PEMKeyPair.getPrivateKeyInfo方法代码示例

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


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

示例1: readPrivateKey

import org.bouncycastle.openssl.PEMKeyPair; //导入方法依赖的package包/类
private PrivateKey readPrivateKey(String privateKeyPath, String keyPassword) throws IOException {

        FileReader fileReader = new FileReader(privateKeyPath);
        PEMParser keyReader = new PEMParser(fileReader);

        JcaPEMKeyConverter converter = new JcaPEMKeyConverter();
        PEMDecryptorProvider decryptionProv = new JcePEMDecryptorProviderBuilder().build(keyPassword.toCharArray());

        Object keyPair = keyReader.readObject();
        PrivateKeyInfo keyInfo;

        if (keyPair instanceof PEMEncryptedKeyPair) {
            PEMKeyPair decryptedKeyPair = ((PEMEncryptedKeyPair) keyPair).decryptKeyPair(decryptionProv);
            keyInfo = decryptedKeyPair.getPrivateKeyInfo();
        } else {
            keyInfo = ((PEMKeyPair) keyPair).getPrivateKeyInfo();
        }

        keyReader.close();
        return converter.getPrivateKey(keyInfo);
    }
 
开发者ID:abbaspour,项目名称:urmia,代码行数:22,代码来源:HttpSigner.java

示例2: decodePemEncodedPrivateKey

import org.bouncycastle.openssl.PEMKeyPair; //导入方法依赖的package包/类
@Override
public PrivateKey decodePemEncodedPrivateKey(Reader privateKeyReader, String password) {
    try {
        PEMParser pemParser = new PEMParser(privateKeyReader);
        Object keyPair = pemParser.readObject();

        // retrieve the PrivateKeyInfo from the returned keyPair object. if the key is encrypted, it needs to be
        // decrypted using the specified password first.
        PrivateKeyInfo keyInfo;
        if (keyPair instanceof PEMEncryptedKeyPair) {
            if (password == null) {
                throw new ImportException("Unable to import private key. Key is encrypted, but no password was provided.");
            }

            PEMDecryptorProvider decryptor = new JcePEMDecryptorProviderBuilder().build(password.toCharArray());

            PEMKeyPair decryptedKeyPair = ((PEMEncryptedKeyPair) keyPair).decryptKeyPair(decryptor);

            keyInfo = decryptedKeyPair.getPrivateKeyInfo();
        } else {
            keyInfo = ((PEMKeyPair) keyPair).getPrivateKeyInfo();
        }

        return new JcaPEMKeyConverter().getPrivateKey(keyInfo);
    } catch (IOException e) {
        throw new ImportException("Unable to read PEM-encoded PrivateKey", e);
    }
}
 
开发者ID:misakuo,项目名称:Dream-Catcher,代码行数:29,代码来源:BouncyCastleSecurityProviderTool.java

示例3: extractRSAKeyPair

import org.bouncycastle.openssl.PEMKeyPair; //导入方法依赖的package包/类
/**
 * makes RSA private key from PEM string.
 *
 * @param s PEM string that contains the key
 * @return
 * @see JCERSAPublicKey
 */
public static RSAKeyPair extractRSAKeyPair(final String s) {
    RSAKeyPair rsaKeyPair;
    try {
        // parse
        final PEMParser parser = new PEMParser(new StringReader(s));
        final Object o = parser.readObject();
        parser.close();
        // check types
        if (!(o instanceof PEMKeyPair)) {
            throw new IOException("Encryption.extractRSAKeyPair: no private key found in string '" + s + "'");
        }
        final PEMKeyPair keyPair = (PEMKeyPair) o;
        if (keyPair.getPrivateKeyInfo() == null) {
            throw new IOException("Encryption.extractRSAKeyPair: no private key found in key pair of string '" + s + "'");
        }
        if (keyPair.getPublicKeyInfo() == null) {
            throw new IOException("Encryption.extractRSAKeyPair: no public key found in key pair of string '" + s + "'");
        }

        // convert keys and pack them together into a key pair
        final RSAPrivateCrtKey privateKey = new TempJCERSAPrivateCrtKey(keyPair.getPrivateKeyInfo());
        logger.debug("JCEPrivateKey={}", privateKey);
        final RSAPublicKey publicKey = new TempJCERSAPublicKey(keyPair.getPublicKeyInfo());
        rsaKeyPair = new RSAKeyPair(publicKey, privateKey);

    } catch (final Exception e) {
        logger.warn("Encryption.extractPrivateRSAKey: Caught exception:" + e.getMessage());
        rsaKeyPair = null;
    }

    return rsaKeyPair;
}
 
开发者ID:rovemonteux,项目名称:silvertunnel-monteux,代码行数:40,代码来源:Encryption.java

示例4: apply

import org.bouncycastle.openssl.PEMKeyPair; //导入方法依赖的package包/类
@Override
public Object apply(Object input) {
  if (input instanceof String && input.toString().contains("BEGIN RSA PRIVATE KEY")) {
    try {
      PEMKeyPair pemKeyPair = (PEMKeyPair) new PEMParser(new StringReader(input.toString())).readObject();
      PrivateKeyInfo privateKeyInfo = pemKeyPair.getPrivateKeyInfo();
      KeyFactory keyFact = KeyFactory.getInstance(
          privateKeyInfo.getPrivateKeyAlgorithm().getAlgorithm().getId(), new BouncyCastleProvider());
      return keyFact.generatePrivate(new PKCS8EncodedKeySpec(privateKeyInfo.getEncoded()));
    } catch (Exception ex) {
      return input;
    }
  }
  return input;
}
 
开发者ID:Netflix,项目名称:denominator,代码行数:16,代码来源:Denominator.java

示例5: getPrivateKey

import org.bouncycastle.openssl.PEMKeyPair; //导入方法依赖的package包/类
public static PrivateKey getPrivateKey(String privateKeyPem) throws IOException {
  PEMParser pemParser = new PEMParser(new StringReader(privateKeyPem));
  PEMKeyPair pemKeyPair = (PEMKeyPair) pemParser.readObject();
  PrivateKeyInfo privateKeyInfo = pemKeyPair.getPrivateKeyInfo();
  return new JcaPEMKeyConverter().getPrivateKey(privateKeyInfo);
}
 
开发者ID:cloudfoundry-incubator,项目名称:credhub,代码行数:7,代码来源:PrivateKeyReader.java


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