/** * Extracts the key pairs within a <U>single</U> delimited by markers block of lines. By * default cleans up the empty lines, joins them and converts them from BASE64 * * @param resourceKey A hint as to the origin of the text lines * @param beginMarker The line containing the begin marker * @param endMarker The line containing the end marker * @param passwordProvider The {@link FilePasswordProvider} to use * in case the data is encrypted - may be {@code null} if no encrypted * @param lines The block of lines between the markers * @return The extracted {@link KeyPair}s - may be {@code null}/empty if none. * @throws IOException If failed to parse the data * @throws GeneralSecurityException If failed to generate the keys * @see #extractKeyPairs(String, String, String, FilePasswordProvider, byte[]) */ public Collection<KeyPair> extractKeyPairs( String resourceKey, String beginMarker, String endMarker, FilePasswordProvider passwordProvider, List<String> lines) throws IOException, GeneralSecurityException { return extractKeyPairs(resourceKey, beginMarker, endMarker, passwordProvider, KeyPairResourceParser.extractDataBytes(lines)); }
/** * Extracts the key pairs within a <U>single</U> delimited by markers block of lines. By * default cleans up the empty lines, joins them and converts them from BASE64 * * @param session The {@link SessionContext} for invoking this load command - may * be {@code null} if not invoked within a session context (e.g., offline tool or session unknown). * @param resourceKey A hint as to the origin of the text lines * @param beginMarker The line containing the begin marker * @param endMarker The line containing the end marker * @param passwordProvider The {@link FilePasswordProvider} to use * in case the data is encrypted - may be {@code null} if no encrypted * @param lines The block of lines between the markers * @return The extracted {@link KeyPair}s - may be {@code null}/empty if none. * @throws IOException If failed to parse the data * @throws GeneralSecurityException If failed to generate the keys */ public Collection<KeyPair> extractKeyPairs( SessionContext session, NamedResource resourceKey, String beginMarker, String endMarker, FilePasswordProvider passwordProvider, List<String> lines) throws IOException, GeneralSecurityException { byte[] dataBytes = KeyPairResourceParser.extractDataBytes(lines); try { return extractKeyPairs(session, resourceKey, beginMarker, endMarker, passwordProvider, dataBytes); } finally { Arrays.fill(dataBytes, (byte) 0); // clean up sensitive data a.s.a.p. } }
/** * @param resourceKey A hint as to the origin of the text lines * @param beginMarker The line containing the begin marker * @param endMarker The line containing the end marker * @param passwordProvider The {@link FilePasswordProvider} to use * in case the data is encrypted - may be {@code null} if no encrypted * @param bytes The decoded bytes from the lines containing the data * @return The extracted {@link KeyPair}s - may be {@code null}/empty if none. * @throws IOException If failed to parse the data * @throws GeneralSecurityException If failed to generate the keys * @see #extractKeyPairs(String, String, String, FilePasswordProvider, InputStream) */ public Collection<KeyPair> extractKeyPairs( String resourceKey, String beginMarker, String endMarker, FilePasswordProvider passwordProvider, byte[] bytes) throws IOException, GeneralSecurityException { if (log.isTraceEnabled()) { BufferUtils.dumpHex(getSimplifiedLogger(), Level.FINER, beginMarker, ':', 16, bytes); } try (InputStream bais = new ByteArrayInputStream(bytes)) { return extractKeyPairs(resourceKey, beginMarker, endMarker, passwordProvider, bais); } }
/** * @param session The {@link SessionContext} for invoking this load command - may * be {@code null} if not invoked within a session context (e.g., offline tool or session unknown). * @param resourceKey A hint as to the origin of the text lines * @param beginMarker The line containing the begin marker * @param endMarker The line containing the end marker * @param passwordProvider The {@link FilePasswordProvider} to use * in case the data is encrypted - may be {@code null} if no encrypted * @param bytes The decoded bytes from the lines containing the data * @return The extracted {@link KeyPair}s - may be {@code null}/empty if none. * @throws IOException If failed to parse the data * @throws GeneralSecurityException If failed to generate the keys */ public Collection<KeyPair> extractKeyPairs( SessionContext session, NamedResource resourceKey, String beginMarker, String endMarker, FilePasswordProvider passwordProvider, byte[] bytes) throws IOException, GeneralSecurityException { if (log.isTraceEnabled()) { BufferUtils.dumpHex(getSimplifiedLogger(), Level.FINER, beginMarker, ':', 16, bytes); } try (InputStream bais = new ByteArrayInputStream(bytes)) { return extractKeyPairs(session, resourceKey, beginMarker, endMarker, passwordProvider, bais); } }
String endLine = lines.get(endIndex); Collection<KeyPair> kps = extractKeyPairs(resourceKey, startLine, endLine, passwordProvider, lines.subList(startIndex, endIndex)); if (GenericUtils.isNotEmpty(kps)) { if (GenericUtils.isEmpty(keyPairs)) {
Collection<KeyPair> kps = extractKeyPairs(session, resourceKey, startLine, endLine, passwordProvider, lines.subList(startIndex, endIndex)); if (GenericUtils.isNotEmpty(kps)) {
return super.extractKeyPairs(resourceKey, beginMarker, endMarker, passwordProvider, dataLines);
return super.extractKeyPairs(session, resourceKey, beginMarker, endMarker, passwordProvider, dataLines);