Class Morph
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic StringThis will decrypt a string from an external file if a slash is there.static StringdecryptIfFile(String in) This will decrypt a string from an external file if a slash is there.static Stringstatic booleanisEncrypted(String in) Determine whether a value looks like a value that Morph.encrypt() produced (i.e. it is already-encrypted ciphertext) as opposed to arbitrary plaintext.static Stringkey()static void
-
Field Details
-
ENCRYPT_KEY
- See Also:
-
testMorphKey
if testing, and not relying on morph key being there, use this
-
-
Method Details
-
main
-
encrypt
- Parameters:
in- $objectType$- Returns:
- String
-
decrypt
This will decrypt a string from an external file if a slash is there. Otherwise it will just return the input since it is just what is being looked for- Parameters:
in- $objectType$- Returns:
- String
-
isEncrypted
Determine whether a value looks like a value that Morph.encrypt() produced (i.e. it is already-encrypted ciphertext) as opposed to arbitrary plaintext.This used to be tested by simply seeing whether Morph.decrypt() ran without throwing. That is unreliable: Base64.decodeBase64() silently strips every character that is NOT in the Base64 alphabet, so free-form text (for example a SQL query full of spaces, commas and parentheses) can have its remaining letters/digits decode to a byte array whose length happens to be a valid AES block, "decrypt" to garbage, and thereby be misdetected as ciphertext. That caused config values such as a data-provider-query SQL statement to be silently stored encrypted/masked (GRP false positive).
A real encrypted value is the non-chunked Base64 output of Crypto.encrypt(), so it contains ONLY Base64 alphabet characters (with at most two trailing '=' padding characters) and its length is a multiple of 4. We require that strict shape before we are willing to trust that a successful decrypt means the value was really encrypted.
- Parameters:
in- candidate value (may be null)- Returns:
- true only if in is strict Base64 and decrypts to a non-blank string
-
decryptIfFile
This will decrypt a string from an external file if a slash is there. Otherwise it will just return the input since it is just what is being looked for- Parameters:
in- $objectType$- Returns:
- String
-
key
- Returns:
- the key to encrypt/decrypt
-