Package rs.baselib.crypto
Class Encrypter
java.lang.Object
rs.baselib.crypto.Encrypter
Class for encrypting strings.
- Author:
- ralph
-
Constructor Summary
ConstructorDescriptionEncrypter
(byte[] bytephrase, byte[] salt, int iterationCount) Constructor from passphrase, salt and iteration spec.Encrypter
(char[] passphrase) Constructor from passphrase.Encrypter
(char[] passphrase, byte[] salt) Constructor from passphrase.Constructor from passphrase.Constructor from passphrase.Constructor from passphrase, salt and iteration spec.Constructor from secret key.Constructor from secret key.Encrypter
(Key key, String algorithm, AlgorithmParameterSpec paramSpec) Constructor from secret key.Constructor from secret key. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]
encrypt
(byte[] bytes) Encrypt a byte arrayTakes a single String as an argument and returns an encrypted version of that string.Returns the algorithm.Returns the algorithmParameterSpec.
-
Constructor Details
-
Encrypter
Constructor from secret key.- Parameters:
eCipher
- the cipher to be used
-
Encrypter
Constructor from secret key.- Parameters:
key
- the secret key to be usedalgorithm
- algorithm (key's algorithm will be used if NULL)- Throws:
EncryptionException
- when encrypting algorithm cannot be generated
-
Encrypter
public Encrypter(Key key, String algorithm, AlgorithmParameterSpec paramSpec) throws EncryptionException Constructor from secret key.- Parameters:
key
- the secret key to be usedalgorithm
- algorithm (key's algorithm will be used if NULL)paramSpec
- parameters to the encrypting algorithm (will be generated if NULL)- Throws:
EncryptionException
- when encrypting algorithm cannot be generated
-
Encrypter
public Encrypter(Key key, String algorithm, byte[] salt, int iterationCount) throws EncryptionException Constructor from secret key.- Parameters:
key
- the secret key to be usedalgorithm
- algorithm (key's algorithm will be used if NULL)salt
- salt to be usediterationCount
- number of iterations for encryption- Throws:
EncryptionException
- when encrypting algorithm cannot be generated
-
Encrypter
public Encrypter(byte[] bytephrase, byte[] salt, int iterationCount) throws EncryptionException, UnsupportedEncodingException Constructor from passphrase, salt and iteration spec.- Parameters:
bytephrase
- passphrase to be usedsalt
- salt to be usediterationCount
- number of iterations for encryption- Throws:
EncryptionException
- when encrypting algorithm cannot be generatedUnsupportedEncodingException
- when encoding cannot be found
-
Encrypter
Constructor from passphrase.- Parameters:
passphrase
- passphrase to be used- Throws:
EncryptionException
- when encrypting algorithm cannot be generated
-
Encrypter
Constructor from passphrase.- Parameters:
passphrase
- passphrase to be usedsalt
- salt to be used- Throws:
EncryptionException
- when encrypting algorithm cannot be generated
-
Encrypter
Constructor from passphrase.- Parameters:
passphrase
- passphrase to be used- Throws:
EncryptionException
- when encrypting algorithm cannot be generated
-
Encrypter
Constructor from passphrase.- Parameters:
passphrase
- passphrase to be usedsalt
- salt to be used- Throws:
EncryptionException
- when encrypting algorithm cannot be generated
-
Encrypter
Constructor from passphrase, salt and iteration spec.- Parameters:
passPhrase
- passphrase to be usedsalt
- salt to be usediterationCount
- number of iterations for encryption- Throws:
EncryptionException
- when encrypting algorithm cannot be generated
-
-
Method Details
-
getAlgorithm
Returns the algorithm.- Returns:
- the algorithm
-
getAlgorithmParameterSpec
Returns the algorithmParameterSpec.- Returns:
- the algorithmParameterSpec
-
encrypt
Takes a single String as an argument and returns an encrypted version of that string.- Parameters:
str
- string to be encrypted- Returns:
String
encrypted version of the provided String- Throws:
EncryptionException
- when encryption fails
-
encrypt
Encrypt a byte array- Parameters:
bytes
- bytes to be encrypted- Returns:
byte
encrypted version of the provided array- Throws:
EncryptionException
- when encryption fails
-