public PemObject readPemObject() throws IOException { String line = readLine(); while (line != null && !line.startsWith(BEGIN)) { line = readLine(); } if (line != null) { line = line.substring(BEGIN.length()); int index = line.indexOf('-'); String type = line.substring(0, index); if (index > 0) { return loadObject(type); } } return null; }
public static PemObject readPemObjectFromFile(String keyfilename) throws IOException { Reader inStream; if (VpnProfile.isEmbedded(keyfilename)) inStream = new StringReader(VpnProfile.getEmbeddedContent(keyfilename)); else inStream = new FileReader(new File(keyfilename)); PemReader pr = new PemReader(inStream); PemObject r = pr.readPemObject(); pr.close(); return r; }
private PemObject loadObject(String type) throws IOException { String line; String endMarker = END + type; StringBuilder buf = new StringBuilder(); List headers = new ArrayList(); while ((line = readLine()) != null) { if (line.indexOf(":") >= 0) { int index = line.indexOf(':'); String hdr = line.substring(0, index); String value = line.substring(index + 1).trim(); headers.add(new PemHeader(hdr, value)); continue; } if (line.indexOf(endMarker) != -1) { break; } buf.append(line.trim()); } if (line == null) { throw new IOException(endMarker + " not found"); } return new PemObject(type, headers, Base64.decode(buf.toString())); }
private PemObject loadObject(String type) throws IOException { String line; String endMarker = END + type; StringBuffer buf = new StringBuffer(); List headers = new ArrayList(); while ((line = readLine()) != null) { if (line.indexOf(":") >= 0) { int index = line.indexOf(':'); String hdr = line.substring(0, index); String value = line.substring(index + 1).trim(); headers.add(new PemHeader(hdr, value)); continue; } if (line.indexOf(endMarker) != -1) { break; } buf.append(line.trim()); } if (line == null) { throw new IOException(endMarker + " not found"); } return new PemObject(type, headers, Base64.decode(buf.toString())); }
public PemObject readPemObject() throws IOException { String line = readLine(); while (line != null && !line.startsWith(BEGIN)) { line = readLine(); } if (line != null) { line = line.substring(BEGIN.length()); int index = line.indexOf('-'); String type = line.substring(0, index); if (index > 0) { return loadObject(type); } } return null; }
/** * Parse a PEM-formatted RSA public key * * @param pem The PEM string. * @return The key. * @throws TelehashException If a problem occurs while reading the file. */ public static HashNamePublicKey parseRSAPublicKeyFromStorage( String pem ) throws TelehashException { try { PemReader pemReader = new PemReader(new StringReader(pem)); PemObject pemObject = pemReader.readPemObject(); pemReader.close(); if (pemObject == null) { throw new TelehashException("cannot parse RSA public key PEM file."); } if (! pemObject.getType().equals(RSA_PUBLIC_KEY_PEM_TYPE)) { throw new TelehashException( "RSA public key PEM file of incorrect type \"" + pemObject.getType() + "\"" ); } return new HashNamePublicKeyImpl(PublicKeyFactory.createKey(pemObject.getContent())); } catch (IOException e) { throw new TelehashException(e); } }
private PemObject loadObject(String type) throws IOException { String line; String endMarker = END + type; StringBuffer buf = new StringBuffer(); List headers = new ArrayList(); while ((line = readLine()) != null) { if (line.indexOf(":") >= 0) { int index = line.indexOf(':'); String hdr = line.substring(0, index); String value = line.substring(index + 1).trim(); headers.add(new PemHeader(hdr, value)); continue; } if (line.indexOf(endMarker) != -1) { break; } buf.append(line.trim()); } if (line == null) { throw new IOException(endMarker + " not found"); } return new PemObject(type, headers, Base64.decode(buf.toString())); }
public PemObject readPemObject() throws IOException { String line = readLine(); while (line != null && !line.startsWith(BEGIN)) { line = readLine(); } if (line != null) { line = line.substring(BEGIN.length()); int index = line.indexOf('-'); String type = line.substring(0, index); if (index > 0) { return loadObject(type); } } return null; }