Class Encrypter

java.lang.Object
rs.baselib.crypto.Encrypter

public class Encrypter extends Object
Class for encrypting strings.
Author:
ralph
  • Constructor Details

    • Encrypter

      public Encrypter(Cipher eCipher)
      Constructor from secret key.
      Parameters:
      eCipher - the cipher to be used
    • Encrypter

      public Encrypter(Key key, String algorithm) throws EncryptionException
      Constructor from secret key.
      Parameters:
      key - the secret key to be used
      algorithm - 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 used
      algorithm - 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 used
      algorithm - algorithm (key's algorithm will be used if NULL)
      salt - salt to be used
      iterationCount - 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 used
      salt - salt to be used
      iterationCount - number of iterations for encryption
      Throws:
      EncryptionException - when encrypting algorithm cannot be generated
      UnsupportedEncodingException - when encoding cannot be found
    • Encrypter

      public Encrypter(char[] passphrase) throws EncryptionException
      Constructor from passphrase.
      Parameters:
      passphrase - passphrase to be used
      Throws:
      EncryptionException - when encrypting algorithm cannot be generated
    • Encrypter

      public Encrypter(char[] passphrase, byte[] salt) throws EncryptionException
      Constructor from passphrase.
      Parameters:
      passphrase - passphrase to be used
      salt - salt to be used
      Throws:
      EncryptionException - when encrypting algorithm cannot be generated
    • Encrypter

      public Encrypter(String passphrase) throws EncryptionException
      Constructor from passphrase.
      Parameters:
      passphrase - passphrase to be used
      Throws:
      EncryptionException - when encrypting algorithm cannot be generated
    • Encrypter

      public Encrypter(String passphrase, byte[] salt) throws EncryptionException
      Constructor from passphrase.
      Parameters:
      passphrase - passphrase to be used
      salt - salt to be used
      Throws:
      EncryptionException - when encrypting algorithm cannot be generated
    • Encrypter

      public Encrypter(String passPhrase, byte[] salt, int iterationCount) throws EncryptionException
      Constructor from passphrase, salt and iteration spec.
      Parameters:
      passPhrase - passphrase to be used
      salt - salt to be used
      iterationCount - number of iterations for encryption
      Throws:
      EncryptionException - when encrypting algorithm cannot be generated
  • Method Details

    • getAlgorithm

      public String getAlgorithm()
      Returns the algorithm.
      Returns:
      the algorithm
    • getAlgorithmParameterSpec

      public AlgorithmParameterSpec getAlgorithmParameterSpec()
      Returns the algorithmParameterSpec.
      Returns:
      the algorithmParameterSpec
    • encrypt

      public String encrypt(String str) throws EncryptionException
      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

      public byte[] encrypt(byte[] bytes) throws EncryptionException
      Encrypt a byte array
      Parameters:
      bytes - bytes to be encrypted
      Returns:
      byte encrypted version of the provided array
      Throws:
      EncryptionException - when encryption fails