List of usage examples for org.apache.commons.ssl PKCS8Key getDecryptedBytes
public byte[] getDecryptedBytes()
From source file:mx.bigdata.cfdi.security.KeyLoader.java
private static byte[] getBytes(InputStream in, char[] passwd) throws Exception { try {/* w w w . ja va 2 s . c o m*/ PKCS8Key pkcs8 = new PKCS8Key(in, passwd); return pkcs8.getDecryptedBytes(); } finally { in.close(); } }
From source file:facturatron.facturacion.PAC.finkok.ClassicKeyLoader.java
private static byte[] getCertBytes(InputStream in, char[] passwd) throws KeyException, IOException { byte[] bytes = null; try {//from w ww. j ava2 s. com PKCS8Key pkcs8 = new PKCS8Key(in, passwd); bytes = pkcs8.getDecryptedBytes(); } catch (GeneralSecurityException e) { throw new KeyException("La contrasea del certificado no es correcta", e.getCause()); } finally { in.close(); } return bytes; }
From source file:cl.nic.dte.extension.AutorizacionTypeExtensionHandler.java
@SuppressWarnings("unchecked") public static PrivateKey getPrivateKey(AutorizacionType auth, char[] password) throws InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeySpecException, InvalidAlgorithmParameterException, IOException { List<PEMItem> items = PEMUtil.decode(auth.getRSASK().getBytes()); for (PEMItem item : items) { if ("RSA PRIVATE KEY".equals(item.pemType)) { try { PKCS8Key pkcs8 = new PKCS8Key(item.getDerBytes(), password); return Utilities.readPrivateKey(pkcs8.getDecryptedBytes(), "RSA", password); } catch (GeneralSecurityException e) { throw new InvalidKeySpecException(e); }// w w w . j a va 2s. com } } return null; }
From source file:org.apache.kerby.pkix.PkiLoader.java
private PrivateKey doLoadPrivateKey(InputStream inputStream, String password) throws GeneralSecurityException, IOException { if (password == null) { password = ""; }/* w ww . j a va2s . co m*/ // If the provided InputStream is encrypted, we need a password to decrypt // it. If the InputStream is not encrypted, then the password is ignored // (can be null). The InputStream can be DER (raw ASN.1) or PEM (base64). PKCS8Key pkcs8 = new PKCS8Key(inputStream, password.toCharArray()); // If an unencrypted PKCS8 key was provided, then this actually returns // exactly what was originally passed inputStream (with no changes). If an OpenSSL // key was provided, it gets reformatted as PKCS #8 first, and so these // bytes will still be PKCS #8, not OpenSSL. byte[] decrypted = pkcs8.getDecryptedBytes(); PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(decrypted); // A Java PrivateKey object is born. PrivateKey pk = null; if (pkcs8.isDSA()) { pk = KeyFactory.getInstance("DSA").generatePrivate(spec); } else if (pkcs8.isRSA()) { pk = KeyFactory.getInstance("RSA").generatePrivate(spec); } // For lazier types: pk = pkcs8.getPrivateKey(); return pk; }
From source file:org.haox.pki.Pkix.java
public static PrivateKey getPrivateKey(InputStream inputStream, String password) throws GeneralSecurityException, IOException { if (password == null) password = ""; // If the provided InputStream is encrypted, we need a password to decrypt // it. If the InputStream is not encrypted, then the password is ignored // (can be null). The InputStream can be DER (raw ASN.1) or PEM (base64). PKCS8Key pkcs8 = new PKCS8Key(inputStream, password.toCharArray()); // If an unencrypted PKCS8 key was provided, then this actually returns // exactly what was originally passed inputStream (with no changes). If an OpenSSL // key was provided, it gets reformatted as PKCS #8 first, and so these // bytes will still be PKCS #8, not OpenSSL. byte[] decrypted = pkcs8.getDecryptedBytes(); PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(decrypted); // A Java PrivateKey object is born. PrivateKey pk = null;//from w w w. j av a 2 s .c o m if (pkcs8.isDSA()) { pk = KeyFactory.getInstance("DSA").generatePrivate(spec); } else if (pkcs8.isRSA()) { pk = KeyFactory.getInstance("RSA").generatePrivate(spec); } // For lazier types: pk = pkcs8.getPrivateKey(); return pk; }