Class EncodeService

java.lang.Object
com.almis.awe.config.ServiceConfig
com.almis.awe.service.EncodeService
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware

public class EncodeService extends ServiceConfig
Encode Service Class Encode Utilities for awe
Author:
Pablo GARCIA - 17/MAR/2011
  • Constructor Details

    • EncodeService

      public EncodeService(BaseConfigProperties baseConfigProperties, SecurityConfigProperties securityConfigProperties)
      Hide the constructor
      Parameters:
      baseConfigProperties - Base config properties
      securityConfigProperties - Security config properties
  • Method Details

    • encodeRipEmd160

      public static String encodeRipEmd160(String text)
      Encodes a text in RIPEMD-160
      Parameters:
      text - Text to encode
      Returns:
      Text encoded
    • decryptRipEmd160

      public String decryptRipEmd160(String text) throws AWException
      Decrypts a string with RipEmd160
      Parameters:
      text - String to be decrypted
      Returns:
      String decrypted
      Throws:
      AWException - Error in decryption
    • encryptRipEmd160

      public String encryptRipEmd160(String text) throws AWException
      Encrypts a string with RipEmd160
      Parameters:
      text - String to be encrypted
      Returns:
      String encrypted
      Throws:
      AWException - Error in encryption
    • encryptRipEmd160WithPhraseKey

      public String encryptRipEmd160WithPhraseKey(String text, String phraseKey) throws AWException
      Encrypts a string with RipEmd160 and phraseKey
      Parameters:
      text - String to be encrypted
      phraseKey - Phrase key
      Returns:
      String encrypted
      Throws:
      AWException - Error in encryption
    • encryptRipEmd160WithPhraseKey

      public String encryptRipEmd160WithPhraseKey(String text, String phraseKey, String encoding) throws AWException
      Encrypts a string with RipEmd160 and phraseKey
      Parameters:
      text - String to be encrypted
      phraseKey - Phrase key
      encoding - Encoding
      Returns:
      String encrypted
      Throws:
      AWException - Error in encryption
    • decryptRipEmd160WithPhraseKey

      public String decryptRipEmd160WithPhraseKey(String text, String phraseKey, String encoding) throws AWException
      Decrypts a string with RipEmd160 and phraseKey
      Parameters:
      text - String to be decrypted
      phraseKey - Phrase key
      encoding - Encoding
      Returns:
      String decrypted
      Throws:
      AWException - Error in decryption
    • decryptAes

      public String decryptAes(String text) throws AWException
      Decrypts a string with Aes
      Parameters:
      text - String to be decrypted
      Returns:
      String decrypted
      Throws:
      AWException - Error in decryption
    • decryptAes

      public String decryptAes(String text, String password) throws AWException
      Decrypts a string with Aes
      Parameters:
      text - String to be decrypted
      password - Password
      Returns:
      String decrypted
      Throws:
      AWException - Error in decryption
    • encryptAes

      public String encryptAes(String text) throws AWException
      Encrypts a string with Aes
      Parameters:
      text - String to be encrypted
      Returns:
      String encrypted
      Throws:
      AWException - Error in encryption
    • encryptAes

      public String encryptAes(String text, String password) throws AWException
      Encrypts a string with Aes
      Parameters:
      text - String to be encrypted
      password - Password
      Returns:
      String encrypted
      Throws:
      AWException - Error in encryption
    • encodeSymmetric

      public static String encodeSymmetric(byte[] encodeValue) throws AWException
      Encodes a text in DES (Symmetric)
      Parameters:
      encodeValue - Text to encode
      Returns:
      Text encoded
      Throws:
      AWException - Error in encoding
    • encodeSymmetric

      public static String encodeSymmetric(String text) throws AWException
      Encodes a text in DES (Symmetric)
      Parameters:
      text - Text to encode
      Returns:
      Text encoded
      Throws:
      AWException - Error in encoding
    • decodeSymmetric

      public String decodeSymmetric(String text) throws AWException
      Decodes a text in DES (Symmetric)
      Parameters:
      text - Text to decode
      Returns:
      Text decoded
      Throws:
      AWException - Error in decoding
    • decodeSymmetricAsByteArray

      public byte[] decodeSymmetricAsByteArray(String text) throws AWException
      Decodes a text in DES (Symmetric)
      Parameters:
      text - Text to decode
      Returns:
      Text decoded
      Throws:
      AWException - Error in decoding
    • encodeHex

      public String encodeHex(String text) throws AWException
      Encodes a text in Hex
      Parameters:
      text - Text to encode
      Returns:
      Text encoded
      Throws:
      AWException - Error encoding
    • decodeHex

      public String decodeHex(String text) throws AWException
      Decodes a text in Hex
      Parameters:
      text - Text to decode
      Returns:
      Text decoded
      Throws:
      AWException - Error decoding
    • encodeTransmission

      public String encodeTransmission(String text, boolean active) throws AWException
      Decodes a text in DES (Symmetric)
      Parameters:
      text - Text to decode
      active - Encoding enabled
      Returns:
      Text decoded
      Throws:
      AWException - Error encoding
    • decodeTransmission

      public String decodeTransmission(String text, boolean active) throws AWException
      Decodes a text in DES (Symmetric)
      Parameters:
      text - Text to decode
      active - Encoding enabled
      Returns:
      Text decoded
      Throws:
      AWException - Error decoding
    • hash

      public String hash(String algorithm, String text) throws AWException
      Hashes a String with an SHA-X algorithm without any salt, where X is the algorithm given in the algorithm variable
      Parameters:
      algorithm - Algorithm
      text - Text to hash
      Returns:
      String Hexadecimal format of the output bytearray
      Throws:
      AWException - Error hashing
    • hash

      public String hash(String algorithm, String text, String salt) throws AWException
      Hashes a String with an SHA-X algorithm with a salt, where X is the algorithm given in the algorithm variable
      Parameters:
      algorithm - Algorithm
      text - Text to hash
      salt - The salt to be applied to the algorithm
      Returns:
      String Hexadecimal format of the output bytearray
      Throws:
      AWException - Error hashing
    • encodePBKDF2WithHmacSHA1

      public String encodePBKDF2WithHmacSHA1(String text) throws AWException
      Hashes a String with a PBKDF2 algorithm based on SHA-1
      Parameters:
      text - Text to encode
      Returns:
      String in Hexadecimal format
      Throws:
      AWException - Error encoding
    • encodePBKDF2WithHmacSHA1

      public String encodePBKDF2WithHmacSHA1(String text, String salt) throws AWException
      Hashes a String with a PBKDF2 algorithm based on SHA-1
      Parameters:
      text - Text to encode
      salt - should be of about 160 bit size or more to create a strong salt
      Returns:
      String in Hexadecimal format
      Throws:
      AWException - Error encoding
    • encodePBKDF2WithHmacSHA1

      public String encodePBKDF2WithHmacSHA1(String text, String salt, int iterations) throws AWException
      Hashes a String with a PBKDF2 algorithm based on SHA-1
      Parameters:
      text - Text to encode
      salt - should be of about 160 bit size or more to create a strong salt
      iterations - Number of iterations
      Returns:
      String in Hexadecimal format
      Throws:
      AWException - Error encoding
    • encodePBKDF2WithHmacSHA1

      public String encodePBKDF2WithHmacSHA1(String text, String salt, int iterations, int keyLength) throws AWException
      Hashes a String with a PBKDF2 algorithm based on SHA-1
      Parameters:
      text - Text to encode
      salt - should be of about 160 bit size or more to create a strong salt
      iterations - recommended value is 256000 in 2016, double this value every 2 years
      keyLength - should not be bigger than the maximum output length of the SHA-1 algorithm which is 160 bit (40 hex characters)
      Returns:
      String in Hexadecimal format
      Throws:
      AWException - Error encoding
    • getSecureRandom

      public static SecureRandom getSecureRandom()
      generate secure random object
      Returns:
      Secure random
    • getSecureRandomString

      public String getSecureRandomString()
      Create a secure random string of the given length with the alphabet
      Returns:
      Random string
    • encodeLanguage

      public static String encodeLanguage(String text, String encoding) throws UnsupportedEncodingException
      Encode given text to the given encoding
      Parameters:
      text - Text to encode
      encoding - Encoding
      Returns:
      Text encoded
      Throws:
      UnsupportedEncodingException - Error encoding
    • encrypt

      public String encrypt(String digest, String valueEnc, String secretKey)
      Symmetric encryption
      Parameters:
      digest - Digest
      valueEnc - Value to encode
      secretKey - Key
      Returns:
      Value encoded
    • decrypt

      public String decrypt(String digest, String encryptedValue, String secretKey)
      Symmetric decryption
      Parameters:
      digest - Digest
      encryptedValue - Encrypted value
      secretKey - Key
      Returns:
      Decrypted value
    • base64Encode

      public static String base64Encode(String text)
      Base64 encode string
      Parameters:
      text - Text to encode
      Returns:
      Text encoded
    • base64Encode

      public static String base64Encode(byte[] text)
      Base64 encode byte array
      Parameters:
      text - Text to encode
      Returns:
      Text encoded
    • base64Decode

      public String base64Decode(String text) throws UnsupportedEncodingException
      Base64 decode string
      Parameters:
      text - Text to decode
      Returns:
      Text decoded
      Throws:
      UnsupportedEncodingException - unsupported encoding exception
    • base64DecodeAsByteArray

      public byte[] base64DecodeAsByteArray(String text)
      Base64 decode string
      Parameters:
      text - Text to decode
      Returns:
      Text decoded
    • base64Decode

      public String base64Decode(byte[] text) throws UnsupportedEncodingException
      Base64 decode byte array
      Parameters:
      text - Text to decode
      Returns:
      Text decoded
      Throws:
      UnsupportedEncodingException - unsupported encoding exception