Package rs.baselib.crypto
Class Encrypter
java.lang.Object
rs.baselib.crypto.Encrypter
public class Encrypter
extends java.lang.Object
Class for encrypting strings.
- Author:
- ralph
-
Constructor Summary
Constructors Constructor Description Encrypter(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.Encrypter(java.lang.String passphrase)Constructor from passphrase.Encrypter(java.lang.String passphrase, byte[] salt)Constructor from passphrase.Encrypter(java.lang.String passPhrase, byte[] salt, int iterationCount)Constructor from passphrase, salt and iteration spec.Encrypter(java.security.Key key, java.lang.String algorithm)Constructor from secret key.Encrypter(java.security.Key key, java.lang.String algorithm, byte[] salt, int iterationCount)Constructor from secret key.Encrypter(java.security.Key key, java.lang.String algorithm, java.security.spec.AlgorithmParameterSpec paramSpec)Constructor from secret key.Encrypter(javax.crypto.Cipher eCipher)Constructor from secret key. -
Method Summary
Modifier and Type Method Description byte[]encrypt(byte[] bytes)Encrypt a byte arrayjava.lang.Stringencrypt(java.lang.String str)Takes a single String as an argument and returns an encrypted version of that string.java.lang.StringgetAlgorithm()Returns the algorithm.java.security.spec.AlgorithmParameterSpecgetAlgorithmParameterSpec()Returns the algorithmParameterSpec.
-
Constructor Details
-
Encrypter
public Encrypter(javax.crypto.Cipher eCipher)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(java.security.Key key, java.lang.String algorithm, java.security.spec.AlgorithmParameterSpec paramSpec) throws EncryptionExceptionConstructor 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(java.security.Key key, java.lang.String algorithm, byte[] salt, int iterationCount) throws EncryptionExceptionConstructor 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, java.io.UnsupportedEncodingExceptionConstructor 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 generatedjava.io.UnsupportedEncodingException- 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
public Encrypter(java.lang.String passPhrase, byte[] salt, int iterationCount) throws EncryptionExceptionConstructor 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
public java.lang.String getAlgorithm()Returns the algorithm.- Returns:
- the algorithm
-
getAlgorithmParameterSpec
public java.security.spec.AlgorithmParameterSpec 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:
Stringencrypted version of the provided String- Throws:
EncryptionException- when encryption fails
-
encrypt
Encrypt a byte array- Parameters:
bytes- bytes to be encrypted- Returns:
byteencrypted version of the provided array- Throws:
EncryptionException- when encryption fails
-