Package org.flasby.crypto
Class CryptoUtils
java.lang.Object
org.flasby.crypto.CryptoUtils
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
checkPassword
(String candidatePassword, String hash) static byte[]
fromBase64
(String toDecode) static CryptoUtils.CipherPair
generateCipherPair
(char[] passPhrase) generates a new CipherPair which can be used to encrypt and decrypt stuff.static final CryptoUtils.CipherPair
generateCipherPair
(char[] passPhrase, byte[] iv) static final CryptoUtils.CipherPair
generateCipherPair
(char[] passPhrase, byte[] salt, String keyAlgorithm, byte[] iv) static Cipher
generateDeCipher
(char[] passPhrase, byte[] salt, String keyAlgorithm, byte[] iv) final byte[]
hashPassword
(char[] password, byte[] salt, int iterations, int keyLength) static final String
hashPassword
(String password) static void
static String
toBase64
(byte[] toEncode)
-
Field Details
-
DEFAULT_KEY_ALGORITHM
- See Also:
-
DEFAULT_CIPHER
- See Also:
-
ENCODING_CHARSET
- See Also:
-
-
Constructor Details
-
CryptoUtils
public CryptoUtils()
-
-
Method Details
-
main
-
generateCipherPair
generates a new CipherPair which can be used to encrypt and decrypt stuff. Importantly, the IV is random so you can't decrypt anything using a new pair with the same passPhrase without first initialising the decrypt IV.- Parameters:
passPhrase
-- Returns:
- Throws:
SecurityException
-
generateCipherPair
public static final CryptoUtils.CipherPair generateCipherPair(char[] passPhrase, byte[] iv) throws SecurityException - Throws:
SecurityException
-
generateCipherPair
public static final CryptoUtils.CipherPair generateCipherPair(char[] passPhrase, byte[] salt, String keyAlgorithm, byte[] iv) throws SecurityException - Throws:
SecurityException
-
generateDeCipher
public static Cipher generateDeCipher(char[] passPhrase, byte[] salt, String keyAlgorithm, byte[] iv) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException -
hashPassword
-
checkPassword
-
hashPassword
public final byte[] hashPassword(char[] password, byte[] salt, int iterations, int keyLength) -
toBase64
-
fromBase64
-