public class CipherUtility extends Object
| Modifier and Type | Field and Description |
|---|---|
static int |
BUFFER_SIZE |
private static int |
DEFAULT_MAX_ALLOWED_KEY_LENGTH |
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 String |
encodeBase64NoPadding(byte[] bytes) |
private static int |
getDefaultKeyLengthForCipher(String cipher) |
static int |
getIterationCountForAlgorithm(String algorithm)
Returns the KDF iteration count for various PBE algorithms.
|
static int |
getMaximumPasswordLengthForAlgorithmOnLimitedStrengthCrypto(EncryptionMethod encryptionMethod) |
static int |
getSaltLengthForAlgorithm(String algorithm)
Returns the salt length for various PBE algorithms.
|
static List<Integer> |
getValidKeyLengthsForAlgorithm(String algorithm)
Returns a list of valid key lengths in bits for this algorithm.
|
static Cipher |
initPBECipher(String algorithm,
String provider,
String password,
byte[] salt,
int iterationCount,
boolean encryptMode)
Initializes a
Cipher object with the given PBE parameters. |
static boolean |
isKeyedCipher(String algorithm) |
static boolean |
isPBECipher(String algorithm) |
static boolean |
isUnlimitedStrengthCryptoSupported() |
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
private static final Map<String,Integer> MAX_PASSWORD_LENGTH_BY_ALGORITHM
private static final int DEFAULT_MAX_ALLOWED_KEY_LENGTH
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)
algorithm - the name of the algorithmprivate 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
IOExceptionProcessExceptionpublic static void writeBytesToOutputStream(OutputStream out, byte[] value, String label, byte[] delimiter) throws IOException
IOExceptionpublic static String encodeBase64NoPadding(byte[] bytes)
public static boolean passwordLengthIsValidForAlgorithmOnLimitedStrengthCrypto(int passwordLength,
EncryptionMethod encryptionMethod)
public static int getMaximumPasswordLengthForAlgorithmOnLimitedStrengthCrypto(EncryptionMethod encryptionMethod)
public static boolean isUnlimitedStrengthCryptoSupported()
public static boolean isPBECipher(String algorithm)
public static boolean isKeyedCipher(String algorithm)
public static Cipher initPBECipher(String algorithm, String provider, String password, byte[] salt, int iterationCount, boolean encryptMode) throws IllegalArgumentException
Cipher object with the given PBE parameters.algorithm - the algorithmprovider - the JCA providerpassword - the passwordsalt - the saltiterationCount - the KDF iteration countencryptMode - true to encrypt; false to decryptIllegalArgumentException - if any parameter is invalidpublic static int getIterationCountForAlgorithm(String algorithm)
StringEncryptorTest#testPBEncryptionShouldBeExternallyConsistent.algorithm - the EncryptionMethod.algorithmpublic static int getSaltLengthForAlgorithm(String algorithm)
StringEncryptorTest#testPBEncryptionShouldBeExternallyConsistent.algorithm - the EncryptionMethod.algorithmCopyright © 2019 Apache NiFi Project. All rights reserved.