Package org.bouncycastle.openssl

Examples of org.bouncycastle.openssl.PEMKeyPair


            PEMParser pemParser = new PEMParser(new FileReader(sslKeyFile));
            Object parsedObject = pemParser.readObject();
            if (!(parsedObject instanceof PEMKeyPair))
                throw new IllegalArgumentException("invalid key file contents");

            PEMKeyPair keyPair = (PEMKeyPair) parsedObject;
            RSAPrivateKey privateKey = (RSAPrivateKey) BouncyCastleProvider.getPrivateKey(keyPair.getPrivateKeyInfo());
            if (privateKey == null)
                throw new IllegalArgumentException("invalid key file contents");
            return privateKey;
        }
View Full Code Here


                return convertKeyPair((PEMKeyPair)po);
            }
            if (po instanceof PEMEncryptedKeyPair) {
                PEMDecryptorProvider dec =
                    new JcePEMDecryptorProviderBuilder().build(passphrase);
                PEMKeyPair kp = ((PEMEncryptedKeyPair)po).decryptKeyPair(dec);
                return convertKeyPair(kp);
            }
            throw new CryptoException("Input data does not contain a key pair");
        } finally {
            pp.close();
View Full Code Here

        addCA(keyStore, certPath + "/ca.pem");
        return keyStore;
    }

    public static PrivateKey loadPrivateKey(String keyPath) throws IOException, GeneralSecurityException {
        PEMKeyPair keyPair = loadPEM(keyPath);
        PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyPair.getPrivateKeyInfo().getEncoded());
        return KeyFactory.getInstance("RSA").generatePrivate(keySpec);
    }
View Full Code Here

  private final RSASha1SignatureService signatureService;

  public XeroOAuthService(Reader reader) {
    Security.addProvider(new BouncyCastleProvider());
    try (PEMParser pemParser = new PEMParser(reader)) {
      PEMKeyPair pair = (PEMKeyPair) pemParser.readObject();
      byte[] encodedPrivateKey = pair.getPrivateKeyInfo().getEncoded();
      KeyFactory keyFactory = KeyFactory.getInstance("RSA");
      PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(encodedPrivateKey);
      PrivateKey privateKey = keyFactory.generatePrivate(privateKeySpec);
      signatureService = new RSASha1SignatureService(privateKey);
    } catch(IOException e) {
View Full Code Here

TOP

Related Classes of org.bouncycastle.openssl.PEMKeyPair

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.