Package com.almis.awe.service
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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
EncodeService.HashingAlgorithms
Static class to store hashing algorithms to make the call to these algorithms more understandable.
-
Constructor Summary
Constructors Constructor Description EncodeService(BaseConfigProperties baseConfigProperties, SecurityConfigProperties securityConfigProperties)
Hide the constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
base64Decode(byte[] text)
Base64 decode byte arrayString
base64Decode(String text)
Base64 decode stringbyte[]
base64DecodeAsByteArray(String text)
Base64 decode stringstatic String
base64Encode(byte[] text)
Base64 encode byte arraystatic String
base64Encode(String text)
Base64 encode stringString
decodeHex(String text)
Decodes a text in HexString
decodeSymmetric(String text)
Decodes a text in DES (Symmetric)byte[]
decodeSymmetricAsByteArray(String text)
Decodes a text in DES (Symmetric)String
decodeTransmission(String text, boolean active)
Decodes a text in DES (Symmetric)String
decrypt(String digest, String encryptedValue, String secretKey)
Symmetric decryptionString
decryptAes(String text)
Decrypts a string with AesString
decryptAes(String text, String password)
Decrypts a string with AesString
decryptRipEmd160(String text)
Decrypts a string with RipEmd160String
decryptRipEmd160WithPhraseKey(String text, String phraseKey, String encoding)
Decrypts a string with RipEmd160 and phraseKeyString
encodeHex(String text)
Encodes a text in Hexstatic String
encodeLanguage(String text, String encoding)
Encode given text to the given encodingString
encodePBKDF2WithHmacSHA1(String text)
Hashes a String with a PBKDF2 algorithm based on SHA-1String
encodePBKDF2WithHmacSHA1(String text, String salt)
Hashes a String with a PBKDF2 algorithm based on SHA-1String
encodePBKDF2WithHmacSHA1(String text, String salt, int iterations)
Hashes a String with a PBKDF2 algorithm based on SHA-1String
encodePBKDF2WithHmacSHA1(String text, String salt, int iterations, int keyLength)
Hashes a String with a PBKDF2 algorithm based on SHA-1static String
encodeRipEmd160(String text)
Encodes a text in RIPEMD-160static String
encodeSymmetric(byte[] encodeValue)
Encodes a text in DES (Symmetric)static String
encodeSymmetric(String text)
Encodes a text in DES (Symmetric)String
encodeTransmission(String text, boolean active)
Decodes a text in DES (Symmetric)String
encrypt(String digest, String valueEnc, String secretKey)
Symmetric encryptionString
encryptAes(String text)
Encrypts a string with AesString
encryptAes(String text, String password)
Encrypts a string with AesString
encryptRipEmd160(String text)
Encrypts a string with RipEmd160String
encryptRipEmd160WithPhraseKey(String text, String phraseKey)
Encrypts a string with RipEmd160 and phraseKeyString
encryptRipEmd160WithPhraseKey(String text, String phraseKey, String encoding)
Encrypts a string with RipEmd160 and phraseKeystatic SecureRandom
getSecureRandom()
generate secure random objectString
getSecureRandomString()
Create a secure random string of the given length with the alphabetString
hash(String algorithm, String text)
Hashes a String with an SHA-X algorithm without any salt, where X is the algorithm given in the algorithm variableString
hash(String algorithm, String text, String salt)
Hashes a String with an SHA-X algorithm with a salt, where X is the algorithm given in the algorithm variable-
Methods inherited from class com.almis.awe.config.ServiceConfig
containsBean, getApplicationContext, getBean, getBean, getElements, getLocale, getLocale, getProperty, getProperty, getRequest, getSession, setApplicationContext
-
-
-
-
Constructor Detail
-
EncodeService
public EncodeService(BaseConfigProperties baseConfigProperties, SecurityConfigProperties securityConfigProperties)
Hide the constructor- Parameters:
baseConfigProperties
- Base config propertiessecurityConfigProperties
- Security config properties
-
-
Method Detail
-
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 encryptedphraseKey
- 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 encryptedphraseKey
- Phrase keyencoding
- 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 decryptedphraseKey
- Phrase keyencoding
- 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 decryptedpassword
- 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 encryptedpassword
- 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 decodeactive
- 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 decodeactive
- 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
- Algorithmtext
- 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
- Algorithmtext
- Text to hashsalt
- 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 encodesalt
- 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 encodesalt
- should be of about 160 bit size or more to create a strong saltiterations
- 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 encodesalt
- should be of about 160 bit size or more to create a strong saltiterations
- recommended value is 256000 in 2016, double this value every 2 yearskeyLength
- 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 encodeencoding
- Encoding- Returns:
- Text encoded
- Throws:
UnsupportedEncodingException
- Error encoding
-
encrypt
public String encrypt(String digest, String valueEnc, String secretKey)
Symmetric encryption- Parameters:
digest
- DigestvalueEnc
- Value to encodesecretKey
- Key- Returns:
- Value encoded
-
decrypt
public String decrypt(String digest, String encryptedValue, String secretKey)
Symmetric decryption- Parameters:
digest
- DigestencryptedValue
- Encrypted valuesecretKey
- 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
-
-