/** * 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. } }
encContext.setPassword(password); encContext.setInitVector(initVector); byte[] encryptedData = KeyPairResourceParser.extractDataBytes(dataLines); byte[] decodedData = applyPrivateKeyCipher(encryptedData, encContext, false); try (InputStream bais = new ByteArrayInputStream(decodedData)) {
byte[] decodedData = GenericUtils.EMPTY_BYTE_ARRAY; try { encryptedData = KeyPairResourceParser.extractDataBytes(dataLines); decodedData = applyPrivateKeyCipher(encryptedData, encContext, false); try (InputStream bais = new ByteArrayInputStream(decodedData)) {