public class CipherUtility extends Object
Modifier and Type | Field and Description |
---|---|
static int |
BUFFER_SIZE |
private static Pattern |
KEY_LENGTH_PATTERN |
private static Map<String,Integer> |
MAX_PASSWORD_LENGTH_BY_ALGORITHM |
Constructor and Description |
---|
CipherUtility() |
Modifier and Type | Method and Description |
---|---|
static byte[] |
concatBytes(byte[]... arrays) |
static String |
encodeBase64NoPadding(byte[] bytes) |
private static int |
getDefaultKeyLengthForCipher(String cipher) |
static int |
getMaximumPasswordLengthForAlgorithmOnLimitedStrengthCrypto(EncryptionMethod encryptionMethod) |
static List<Integer> |
getValidKeyLengthsForAlgorithm(String algorithm) |
static boolean |
isValidKeyLength(int keyLength,
String cipher)
Returns true if the provided key length is a valid key length for the provided cipher family.
|
static boolean |
isValidKeyLengthForAlgorithm(int keyLength,
String algorithm)
Returns true if the provided key length is a valid key length for the provided algorithm.
|
private static int |
parseActualKeyLengthFromAlgorithm(String algorithm) |
static String |
parseCipherFromAlgorithm(String algorithm)
Returns the cipher algorithm from the full algorithm name.
|
static int |
parseKeyLengthFromAlgorithm(String algorithm)
Returns the cipher key length from the full algorithm name.
|
static boolean |
passwordLengthIsValidForAlgorithmOnLimitedStrengthCrypto(int passwordLength,
EncryptionMethod encryptionMethod) |
static void |
processStreams(Cipher cipher,
InputStream in,
OutputStream out) |
static byte[] |
readBytesFromInputStream(InputStream in,
String label,
int limit,
byte[] delimiter) |
static void |
writeBytesToOutputStream(OutputStream out,
byte[] value,
String label,
byte[] delimiter) |
public static final int BUFFER_SIZE
private static final Pattern KEY_LENGTH_PATTERN
public static String parseCipherFromAlgorithm(String algorithm)
algorithm
- the full algorithm namepublic static int parseKeyLengthFromAlgorithm(String algorithm)
algorithm
- the full algorithm nameprivate static int parseActualKeyLengthFromAlgorithm(String algorithm)
public static boolean isValidKeyLength(int keyLength, String cipher)
AES/CBC/PKCS7Padding
but not PBEWITHMD5AND128BITAES-CBC-OPENSSL
. However, this method will return true
for both because it only gets the cipher
family, AES
.
64, AES -> false
[128, 192, 256], AES -> truekeyLength
- the key length in bitscipher
- the cipher familypublic static boolean isValidKeyLengthForAlgorithm(int keyLength, String algorithm)
AES/CBC/PKCS7Padding
but not PBEWITHMD5AND128BITAES-CBC-OPENSSL
.
64, AES/CBC/PKCS7Padding -> false
[128, 192, 256], AES/CBC/PKCS7Padding -> true
128, PBEWITHMD5AND128BITAES-CBC-OPENSSL -> true
[192, 256], PBEWITHMD5AND128BITAES-CBC-OPENSSL -> falsekeyLength
- the key length in bitsalgorithm
- the specific algorithmpublic static List<Integer> getValidKeyLengthsForAlgorithm(String algorithm)
private static int getDefaultKeyLengthForCipher(String cipher)
public static void processStreams(Cipher cipher, InputStream in, OutputStream out)
public static byte[] readBytesFromInputStream(InputStream in, String label, int limit, byte[] delimiter) throws IOException, ProcessException
IOException
ProcessException
public static void writeBytesToOutputStream(OutputStream out, byte[] value, String label, byte[] delimiter) throws IOException
IOException
public static String encodeBase64NoPadding(byte[] bytes)
public static boolean passwordLengthIsValidForAlgorithmOnLimitedStrengthCrypto(int passwordLength, EncryptionMethod encryptionMethod)
public static int getMaximumPasswordLengthForAlgorithmOnLimitedStrengthCrypto(EncryptionMethod encryptionMethod)
public static byte[] concatBytes(byte[]... arrays) throws IOException
IOException
Copyright © 2017 Apache NiFi Project. All rights reserved.