use of org.bouncycastle.openssl.PEMReader in project MSEC by Tencent.
the class Tools method loadPubKeyFromFile.
public static PublicKey loadPubKeyFromFile(String filename) {
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
try {
FileReader fr = new FileReader(filename);
PEMReader pr = new PEMReader(fr);
PublicKey key = (PublicKey) (pr.readObject());
pr.close();
fr.close();
return key;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
use of org.bouncycastle.openssl.PEMReader in project XobotOS by xamarin.
the class Credentials method convertFromPem.
/**
* Convert objects from PEM format, which is used for
* CA_CERTIFICATE, USER_CERTIFICATE, and USER_PRIVATE_KEY
* entries.
*/
public static List<Object> convertFromPem(byte[] bytes) throws IOException {
ByteArrayInputStream bai = new ByteArrayInputStream(bytes);
Reader reader = new InputStreamReader(bai, Charsets.US_ASCII);
PEMReader pr = new PEMReader(reader);
List<Object> result = new ArrayList<Object>();
Object o;
while ((o = pr.readObject()) != null) {
result.add(o);
}
pr.close();
return result;
}
use of org.bouncycastle.openssl.PEMReader in project OpenAttestation by OpenAttestation.
the class TAHelper method pemToX509Certificate.
/**
* Convert a PEM formatted certificate in X509 format.
* @param machineCertPEM Machine certificate in PEM/text format.
* @return An X509 certificate object.
*/
public static X509Certificate pemToX509Certificate(String machineCertPEM) {
try {
File f = new File(machineCertPEM);
FileInputStream filestr = new FileInputStream(f);
DataInputStream datastr = new DataInputStream(filestr);
byte[] keyBytes = new byte[(int) f.length()];
datastr.readFully(keyBytes);
String temp = new String(keyBytes);
PEMReader reader = new PEMReader(new StringReader(temp.replace("-----BEGIN CERTIFICATE-----", "-----BEGIN CERTIFICATE-----\n").replace("-----END CERTIFICATE-----", "\n-----END CERTIFICATE-----")));
datastr.close();
return (X509Certificate) reader.readObject();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
Aggregations