Package org.bouncycastle.util.io.pem

Examples of org.bouncycastle.util.io.pem.PemReader


      }
    }

    if (key == null) {
      try {
        PemReader reader = new PemReader(new StringReader(s));
        PemObject pemObject = reader.readPemObject();
        reader.close();

        PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(pemObject.getContent());
        KeyFactory kf = KeyFactory.getInstance("RSA");
        PrivateKey privateKey = kf.generatePrivate(keySpec);
        if (privateKey instanceof RSAPrivateCrtKey) {
View Full Code Here


      return null;
    }
  }

  private PKCS10CertificationRequest parsePemFormat(String data) throws IOException {
    PemReader reader = new PemReader(new StringReader(data));
    PemObject pemObject = reader.readPemObject();
    reader.close();

    PKCS10CertificationRequest csr = new PKCS10CertificationRequest(pemObject.getContent());
    return csr;
  }
View Full Code Here

      throw new OpsException("Error reading CSR", e);
    }
  }

  private static PKCS10CertificationRequest parseCsr(String csr) throws IOException {
    PemReader reader = new PemReader(new StringReader(csr));
    PemObject pemObject = reader.readPemObject();
    reader.close();

    PKCS10CertificationRequest csrHolder = new PKCS10CertificationRequest(pemObject.getContent());
    return csrHolder;
  }
View Full Code Here

            return null;
        }
    }

    private PKCS10CertificationRequest parsePemFormat(String data) throws IOException {
        PemReader reader = new PemReader(new StringReader(data));
        PemObject pemObject = reader.readPemObject();
        reader.close();

        PKCS10CertificationRequest csr = new PKCS10CertificationRequest(pemObject.getContent());
        return csr;
    }
View Full Code Here

      if (algorithm == null) {
        throw new IllegalStateException("Could not read key pair algorithm");
      }

      if (privateKeyText.length() > 0) {
        PemReader reader = new PemReader(new StringReader(privateKeyText.toString()));
        PemObject obj = reader.readPemObject();
        reader.close();

        PrivateKeyInfo privateKeyInfo = new PrivateKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, null), RSAPrivateKey.getInstance(obj.getContent()));
        byte[] encoded = privateKeyInfo.getEncoded();

        privateKey = Keys.getPrivateKeyFromPKCS8File(encoded, KeyPairType.RSA);
      }

      if (publicKeyText.length() > 0) {
        PemReader reader = new PemReader(new StringReader(publicKeyText.toString()));
        PemObject obj = reader.readPemObject();
        reader.close();

        byte[] publicKeyBytes = obj.getContent();
        publicKey = Keys.getPublicKeyFromX509File(publicKeyBytes, KeyPairType.RSA);
      }
View Full Code Here

     */
    @Override
    public KeyPair readKeyPair(String algorithm, Reader rdr, char[] passphrase)
        throws CryptoException, IOException
    {
        PemReader reader = new PemReader(rdr);

        PemObject pemObj = reader.readPemObject();
        if (pemObj == null) {
            throw new CryptoException("Not a valid PEM file");
        }

        if (!DSA_TYPE.equals(pemObj.getType())) {
View Full Code Here

  }

  static PublicKey loadPublicKey() throws Exception {

    final KeyFactory keyFactory = KeyFactory.getInstance("RSA");
    final PemReader reader = new PemReader(new InputStreamReader(
        GenerateRSAKeys.class
            .getResourceAsStream("/META-INF/public-johndoe.pem")));
    final byte[] pubKey = reader.readPemObject().getContent();
    final X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(pubKey);
    reader.close();
    PublicKey publicKey = keyFactory.generatePublic(publicKeySpec);
    return publicKey;

  }
View Full Code Here

  }

  static PrivateKey loadPrivateKey(InputStream in) throws Exception {

    final KeyFactory keyFactory = KeyFactory.getInstance("RSA");
    final PemReader reader = new PemReader(new InputStreamReader(in));
    final byte[] pubKey = reader.readPemObject().getContent();
    // final X509EncodedKeySpec publicKeySpec = new
    // X509EncodedKeySpec(pubKey);
    reader.close();
    PKCS8EncodedKeySpec publicKeySpec = new PKCS8EncodedKeySpec(pubKey);
    PrivateKey publicKey = keyFactory.generatePrivate(publicKeySpec);
    return publicKey;
  }
View Full Code Here

  }

  public static PublicKey loadPublicKey(InputStream in) throws Exception {
    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
    final KeyFactory keyFactory = KeyFactory.getInstance("RSA");
    final PemReader reader = new PemReader(new InputStreamReader(in));
    final byte[] pubKey = reader.readPemObject().getContent();
    final X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(pubKey);
    reader.close();
    PublicKey publicKey = keyFactory.generatePublic(publicKeySpec);
    return publicKey;

  }
View Full Code Here

  }

  public static PrivateKey loadPrivateKey(InputStream in) throws Exception {
    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
    final KeyFactory keyFactory = KeyFactory.getInstance("RSA");
    final PemReader reader = new PemReader(new InputStreamReader(in));
    final byte[] pubKey = reader.readPemObject().getContent();
   
    reader.close();
    PKCS8EncodedKeySpec publicKeySpec = new PKCS8EncodedKeySpec(pubKey);
    PrivateKey publicKey = keyFactory.generatePrivate(publicKeySpec);
    return publicKey;
  }
View Full Code Here

TOP

Related Classes of org.bouncycastle.util.io.pem.PemReader

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.