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 array
    java.lang.String encrypt​(java.lang.String str)
    Takes a single String as an argument and returns an encrypted version of that string.
    java.lang.String getAlgorithm()
    Returns the algorithm.
    java.security.spec.AlgorithmParameterSpec getAlgorithmParameterSpec()
    Returns the algorithmParameterSpec.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Encrypter

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

      public Encrypter​(java.security.Key key, java.lang.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​(java.security.Key key, java.lang.String algorithm, java.security.spec.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​(java.security.Key key, java.lang.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, java.io.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
      java.io.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​(java.lang.String passphrase) throws EncryptionException
      Constructor from passphrase.
      Parameters:
      passphrase - passphrase to be used
      Throws:
      EncryptionException - when encrypting algorithm cannot be generated
    • Encrypter

      public Encrypter​(java.lang.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​(java.lang.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 java.lang.String getAlgorithm()
      Returns the algorithm.
      Returns:
      the algorithm
    • getAlgorithmParameterSpec

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

      public java.lang.String encrypt​(java.lang.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