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