public class SecurityUtils extends Object
Modifier and Type | Field and Description |
---|---|
static String |
CIPHER
Cipher
|
static String |
CIPHER_TYPE
Cipher Type
|
static String |
HASH_ALGO
Hash - MD5
|
static Pattern |
SECURITY_XSS_BLACK_PATTERN
If any string matches this pattern in the Result, it case a
SecurityException . |
static Pattern |
SECURITY_XSS_WHITE_PATTERN
If any exception to the BLACK Pattern
|
Constructor and Description |
---|
SecurityUtils() |
Modifier and Type | Method and Description |
---|---|
static Key |
decodeKey(String encodedKey)
Reconstruct a secret key from a string representation.
|
static String |
decrypt(String toDecrypt,
Key key)
This is a decryption Algorithm; it supports double byte characters also
please ensure the encrypt method is used to decrypt whatever is encrypted through this (Not to confuse with URL Decoder) It accepts null parameters |
static String |
decrypt(String toDecrypt,
Key key,
String cipherType)
This is a decryption Algorithm; it supports double byte characters also
please ensure the encrypt method is used to decrypt whatever is encrypted through this (Not to confuse with URL Decoder) It accepts null parameters |
static Key |
deSerializeKey(String serializedKey) |
static String |
encodeKey(Key key)
Encode a secret key as a string that can be stored for later
use.
|
static String |
encrypt(String toEncrypt,
Key key)
This is a decryption Algorithm; it supports double byte characters also
please ensure the decrypt method is used to decrypt whatever is encrypted through this (Not to confuse with URL Encoder) It accepts null parameters |
static String |
encrypt(String toEncrypt,
Key key,
String cipherType)
This is a decryption Algorithm; it supports double byte characters also
please ensure the decrypt method is used to decrypt whatever is encrypted through this (Not to confuse with URL Encoder) It accepts null parameters |
static String |
genRandomString(int len) |
static String |
getHashedId(String id,
int size,
Function<Integer,Boolean> f)
Convert a Sequential unique Id to a String of a specified size.
|
static Key |
getSecretKey()
This method generates a new Key each time it is called
Create a key for use in the cipher code
|
static Key |
getSecretKey(String cipher)
This method generates a new Key each time it is called
Create a key for use in the cipher code
|
static String |
getSecretKeyString()
Generate a 7 byte (56-bit) String
|
static String |
hash(String toEncrypt)
Hashes the string with MD5 algorithm
|
static X509Certificate |
readCertificate(org.springframework.core.io.Resource resource) |
static Object |
secureAgainstXSS(Object value)
Data may come from anywhere, including user interfaces.
|
static String |
serializeKey(Key key) |
public static final String CIPHER_TYPE
public static final String CIPHER
public static final String HASH_ALGO
public static Pattern SECURITY_XSS_BLACK_PATTERN
SecurityException
. Can override during bootup if required.public static Pattern SECURITY_XSS_WHITE_PATTERN
public static Object secureAgainstXSS(Object value) throws SecurityException
value
- as ObjectfieldName
- as String (provided for any conditional checks; optional). Its advised that all checks be on all data without exceptions.SecurityException
public static String encrypt(String toEncrypt, Key key, String cipherType) throws Exception
public static String encrypt(String toEncrypt, Key key) throws Exception
toEncrypt
- as String; if null returns nullkey
- as Key; If null returns the input stringException
public static String decrypt(String toDecrypt, Key key, String cipherType) throws Exception
public static String decrypt(String toDecrypt, Key key) throws Exception
toDecrypt
- as String; if null returns nullkey
- as Key; If null returns the input stringException
public static Key getSecretKey(String cipher) throws NoSuchAlgorithmException
cipher
- as a valid KeyGenerator
typeNoSuchAlgorithmException
public static String serializeKey(Key key) throws IOException
IOException
public static Key deSerializeKey(String serializedKey) throws IOException, ClassNotFoundException
IOException
ClassNotFoundException
public static Key getSecretKey() throws NoSuchAlgorithmException
NoSuchAlgorithmException
public static String encodeKey(Key key)
key
- as Keypublic static Key decodeKey(String encodedKey) throws IOException
encodedKey
- as StringIOException
public static String hash(String toEncrypt) throws Exception
toEncrypt
- Exception
- public static String getSecretKeyString() throws NoSuchAlgorithmException
NoSuchAlgorithmException
public static String getHashedId(String id, int size, Function<Integer,Boolean> f) throws UnsupportedEncodingException, NoSuchAlgorithmException
id
- as String (intended to be unique)size
- as intf
- as Function
that takes in index and returns if it should be a character (true) or number (false)UnsupportedEncodingException
NoSuchAlgorithmException
public static X509Certificate readCertificate(org.springframework.core.io.Resource resource) throws IOException, GeneralSecurityException
IOException
GeneralSecurityException
public static String genRandomString(int len)
Copyright © 2018. All rights reserved.