public static final <C extends PrivateKeyEncryptionContext> C initializeObfuscator(C context, PrivateKeyObfuscator o, String password) { context.setCipherName(o.getCipherName()); context.setPrivateKeyObfuscator(o); context.setPassword(password); return context; } }
@Override public boolean canExtractKeyPairs(NamedResource resourceKey, List<String> lines) throws IOException, GeneralSecurityException { return KeyPairResourceParser.containsMarkerLine(lines, getBeginners()); }
default Collection<KeyPair> loadKeyPairs( SessionContext session, URL url, FilePasswordProvider passwordProvider) throws IOException, GeneralSecurityException { return loadKeyPairs(session, url, passwordProvider, StandardCharsets.UTF_8); }
@Override public byte[] applyPrivateKeyCipher(byte[] bytes, PrivateKeyEncryptionContext encContext, boolean encryptIt) throws GeneralSecurityException { int keyLength = resolveKeyLength(encContext); byte[] keyValue = deriveEncryptionKey(encContext, keyLength / Byte.SIZE); return applyPrivateKeyCipher(bytes, encContext, keyLength, keyValue, encryptIt); }
@Override public byte[] applyPrivateKeyCipher(byte[] bytes, PrivateKeyEncryptionContext encContext, boolean encryptIt) throws GeneralSecurityException { PrivateKeyEncryptionContext effContext = resolveEffectiveContext(encContext); byte[] keyValue = deriveEncryptionKey(effContext, DEFAULT_KEY_LENGTH); return applyPrivateKeyCipher(bytes, effContext, keyValue.length * Byte.SIZE, keyValue, encryptIt); }
public PrivateKeyObfuscator resolvePrivateKeyObfuscator() { PrivateKeyObfuscator value = getPrivateKeyObfuscator(); if (value != null) { return value; } return getRegisteredPrivateKeyObfuscator(getCipherName()); }
@Override public byte[] generateInitializationVector(PrivateKeyEncryptionContext encContext) throws GeneralSecurityException { return generateInitializationVector(resolveKeyLength(encContext)); }
@Override public boolean canExtractKeyPairs(String resourceKey, List<String> lines) throws IOException, GeneralSecurityException { for (KeyPairResourceParser p : parsers) { if (p.canExtractKeyPairs(resourceKey, lines)) { return true; } } return false; }
/** * Attempts to locate a line that contains one of the markers * * @param lines The list of lines to scan - ignored if {@code null}/empty * @param markers The markers to match - ignored if {@code null}/empty * @return A {@link SimpleImmutableEntry} whose key is the <U>first</U> line index * that matched and value the matched marker index - {@code null} if no match found * @see #findMarkerLine(List, int, List) */ static SimpleImmutableEntry<Integer, Integer> findMarkerLine(List<String> lines, List<String> markers) { return findMarkerLine(lines, 0, markers); }
/** * @param algInfo The algorithm info - format: <I>{@code name-type-mode}</I> * @return The updated context instance * @see #parseAlgorithmInfo(PrivateKeyEncryptionContext, String) */ public PrivateKeyEncryptionContext parseAlgorithmInfo(String algInfo) { return parseAlgorithmInfo(this, algInfo); }
@Override protected byte[] generateInitializationVector(int keyLength) { return super.generateInitializationVector(8 * Byte.SIZE); }
public static final <C extends PrivateKeyEncryptionContext> C initializeObfuscator(C context, PrivateKeyObfuscator o, String password) { context.setCipherName(o.getCipherName()); context.setPrivateKeyObfuscator(o); context.setPassword(password); return context; } }
@Override public byte[] applyPrivateKeyCipher( byte[] bytes, PrivateKeyEncryptionContext encContext, boolean encryptIt) throws GeneralSecurityException, IOException { int keyLength = resolveKeyLength(encContext); byte[] keyValue = deriveEncryptionKey(encContext, keyLength / Byte.SIZE); return applyPrivateKeyCipher(bytes, encContext, keyLength, keyValue, encryptIt); }
@Override public byte[] applyPrivateKeyCipher( byte[] bytes, PrivateKeyEncryptionContext encContext, boolean encryptIt) throws GeneralSecurityException, IOException { PrivateKeyEncryptionContext effContext = resolveEffectiveContext(encContext); byte[] keyValue = deriveEncryptionKey(effContext, DEFAULT_KEY_LENGTH); return applyPrivateKeyCipher(bytes, effContext, keyValue.length * Byte.SIZE, keyValue, encryptIt); }
@Override public boolean canExtractKeyPairs(String resourceKey, List<String> lines) throws IOException, GeneralSecurityException { return KeyPairResourceParser.containsMarkerLine(lines, getBeginners()); }
default Collection<KeyPair> loadKeyPairs( SessionContext session, NamedResource resourceKey, FilePasswordProvider passwordProvider, InputStream stream) throws IOException, GeneralSecurityException { return loadKeyPairs(session, resourceKey, passwordProvider, stream, StandardCharsets.UTF_8); }
@Override public boolean canExtractKeyPairs(NamedResource resourceKey, List<String> lines) throws IOException, GeneralSecurityException { for (KeyPairResourceParser p : parsers) { if (p.canExtractKeyPairs(resourceKey, lines)) { return true; } } return false; }
/** * Attempts to locate a line that contains one of the markers * * @param lines The list of lines to scan - ignored if {@code null}/empty * @param markers The markers to match - ignored if {@code null}/empty * @return A {@link SimpleImmutableEntry} whose key is the <U>first</U> line index * that matched and value the matched marker index - {@code null} if no match found * @see #findMarkerLine(List, int, List) */ static SimpleImmutableEntry<Integer, Integer> findMarkerLine(List<String> lines, List<String> markers) { return findMarkerLine(lines, 0, markers); }
/** * @param algInfo The algorithm info - format: <I>{@code name-type-mode}</I> * @return The updated context instance * @see #parseAlgorithmInfo(PrivateKeyEncryptionContext, String) */ public PrivateKeyEncryptionContext parseAlgorithmInfo(String algInfo) { return parseAlgorithmInfo(this, algInfo); }
default Collection<KeyPair> loadKeyPairs( SessionContext session, IoResource<?> resource, FilePasswordProvider passwordProvider) throws IOException, GeneralSecurityException { return loadKeyPairs(session, resource, passwordProvider, StandardCharsets.UTF_8); }