Java Code Examples for org.bouncycastle.util.io.pem.PemReader#close()

The following examples show how to use org.bouncycastle.util.io.pem.PemReader#close() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PemFile.java    From arcusipcd with Apache License 2.0 5 votes vote down vote up
public PemFile(String filename) throws FileNotFoundException, IOException {
	PemReader pemReader = new PemReader(new InputStreamReader(new FileInputStream(filename)));
	try {
		this.pemObject = pemReader.readPemObject();
	} finally {
		pemReader.close();
	}
}
 
Example 2
Source File: BCECUtil.java    From gmhelper with Apache License 2.0 5 votes vote down vote up
private static byte[] convertPEMToEncodedData(String pemString) throws IOException {
    ByteArrayInputStream bIn = new ByteArrayInputStream(pemString.getBytes());
    PemReader pRdr = new PemReader(new InputStreamReader(bIn));
    try {
        PemObject pemObject = pRdr.readPemObject();
        return pemObject.getContent();
    } finally {
        pRdr.close();
    }
}
 
Example 3
Source File: BCECUtil.java    From littleca with Apache License 2.0 5 votes vote down vote up
private static byte[] convertPemToDerEcData(String pemString) throws IOException {
    ByteArrayInputStream bIn = new ByteArrayInputStream(pemString.getBytes());
    PemReader pRdr = new PemReader(new InputStreamReader(bIn));
    try {
        PemObject pemObject = pRdr.readPemObject();
        return pemObject.getContent();
    } finally {
        pRdr.close();
    }
}
 
Example 4
Source File: PEMManager.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
public void load(InputStream in)
        throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException,
                InvalidKeySpecException, NoSuchProviderException {
    PemReader pemReader = new PemReader(new InputStreamReader(in));

    pem = pemReader.readPemObject();
    if (pem == null) {
        throw new IOException("The file does not represent a pem account.");
    }

    // logger.debug(" load pem, type: {}, header: {}", pem.getType(), pem.getHeaders());

    pemReader.close();
}
 
Example 5
Source File: SecurityHelper.java    From MQTT-Essentials-A-Lightweight-IoT-Protocol with MIT License 5 votes vote down vote up
private static PrivateKey createPrivateKeyFromPemFile(final String keyFileName) throws IOException, InvalidKeySpecException, NoSuchAlgorithmException 
{
	// Loads a privte key from the specified key file name
    final PemReader pemReader = new PemReader(new FileReader(keyFileName));
    final PemObject pemObject = pemReader.readPemObject();
    final byte[] pemContent = pemObject.getContent();
    pemReader.close();
    final PKCS8EncodedKeySpec encodedKeySpec = new PKCS8EncodedKeySpec(pemContent);
    final KeyFactory keyFactory = getKeyFactoryInstance();
    final PrivateKey privateKey = keyFactory.generatePrivate(encodedKeySpec);
    return privateKey;
}
 
Example 6
Source File: SecurityHelper.java    From MQTT-Essentials-A-Lightweight-IoT-Protocol with MIT License 5 votes vote down vote up
private static PrivateKey createPrivateKeyFromPemFile(final String keyFileName) throws IOException, InvalidKeySpecException, NoSuchAlgorithmException 
{
	// Loads a privte key from the specified key file name
    final PemReader pemReader = new PemReader(new FileReader(keyFileName));
    final PemObject pemObject = pemReader.readPemObject();
    final byte[] pemContent = pemObject.getContent();
    pemReader.close();
    final PKCS8EncodedKeySpec encodedKeySpec = new PKCS8EncodedKeySpec(pemContent);
    final KeyFactory keyFactory = getKeyFactoryInstance();
    final PrivateKey privateKey = keyFactory.generatePrivate(encodedKeySpec);
    return privateKey;
}
 
Example 7
Source File: PemFile.java    From azure-keyvault-java with MIT License 5 votes vote down vote up
public PemFile(String filename) throws FileNotFoundException, IOException {
    PemReader pemReader = new PemReader(new InputStreamReader(new FileInputStream(filename)));
    try {
        this.pemObject = pemReader.readPemObject();
    } finally {
        pemReader.close();
    }
}
 
Example 8
Source File: BCECUtil.java    From jiguang-java-client-common with MIT License 5 votes vote down vote up
private static byte[] convertPEMToEncodedData(String pemString) throws IOException {
    ByteArrayInputStream bIn = new ByteArrayInputStream(pemString.getBytes());
    PemReader pRdr = new PemReader(new InputStreamReader(bIn));
    try {
        PemObject pemObject = pRdr.readPemObject();
        return pemObject.getContent();
    } finally {
        pRdr.close();
    }
}
 
Example 9
Source File: PemUtils.java    From java-jwt with MIT License 5 votes vote down vote up
private static byte[] parsePEMFile(File pemFile) throws IOException {
    if (!pemFile.isFile() || !pemFile.exists()) {
        throw new FileNotFoundException(String.format("The file '%s' doesn't exist.", pemFile.getAbsolutePath()));
    }
    PemReader reader = new PemReader(new FileReader(pemFile));
    PemObject pemObject = reader.readPemObject();
    byte[] content = pemObject.getContent();
    reader.close();
    return content;
}