Class DefaultSecureTokenService
- java.lang.Object
-
- de.hybris.platform.commerceservices.security.impl.DefaultSecureTokenService
-
- All Implemented Interfaces:
SecureTokenService,org.springframework.beans.factory.InitializingBean
public class DefaultSecureTokenService extends java.lang.Object implements SecureTokenService, org.springframework.beans.factory.InitializingBean
Default implementation ofSecureTokenService
-
-
Field Summary
Fields Modifier and Type Field Description protected static intAESIV_LENGTHprotected static intENCRYPT_KEY_LENGTHprotected static java.lang.StringENCRYPTION_CIPHERprotected static intMD5_LENGTHprotected static java.lang.StringMESSAGEDIGEST_ALGORITHMprotected static java.lang.StringRANDOM_ALGORITHM
-
Constructor Summary
Constructors Constructor Description DefaultSecureTokenService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterPropertiesSet()protected booleanarrayEquals(byte[] array1, int offset1, byte[] array2, int offset2, int length)protected javax.crypto.spec.SecretKeySpecbuildSecretKey(byte[] encryptionKeyBytes)protected int[]computePaddingLengths()protected java.lang.Stringconvert(byte[] data)protected java.lang.StringcreateChecksum(java.lang.String data)protected byte[]decodeHexString(java.lang.String text)protected byte[]decrypt(java.lang.String encryptedText, byte[] encryptionKeyBytes)SecureTokendecryptData(java.lang.String token)Decrypt the token to a SecureToken.protected java.lang.Stringencrypt(byte[] plainText, byte[] encryptionKeyBytes)java.lang.StringencryptData(SecureToken data)Encrypt the SecureToken parameter to a Stringprotected byte[]generatePadding(int length)protected byte[]generateSignature(byte[] data, int offset, int length, byte[] signatureKeyBytes)protected byte[]getEncryptionKeyBytes()protected java.lang.StringgetEncryptionKeyHex()protected java.security.SecureRandomgetRandom()protected byte[]getSignatureKeyBytes()protected java.lang.StringgetSignatureKeyHex()voidsetEncryptionKeyHex(java.lang.String encryptionKeyHex)voidsetSignatureKeyHex(java.lang.String signatureKeyHex)protected voidskipPadding(java.io.DataInputStream dataInputStream)protected booleanvalidateSignature(byte[] dataBytes, int dataOffset, int dataLength, byte[] signatureBytes, int signatureOffset, byte[] signatureKeyBytes)
-
-
-
Field Detail
-
ENCRYPT_KEY_LENGTH
protected static final int ENCRYPT_KEY_LENGTH
- See Also:
- Constant Field Values
-
MD5_LENGTH
protected static final int MD5_LENGTH
- See Also:
- Constant Field Values
-
AESIV_LENGTH
protected static final int AESIV_LENGTH
- See Also:
- Constant Field Values
-
ENCRYPTION_CIPHER
protected static final java.lang.String ENCRYPTION_CIPHER
- See Also:
- Constant Field Values
-
RANDOM_ALGORITHM
protected static final java.lang.String RANDOM_ALGORITHM
- See Also:
- Constant Field Values
-
MESSAGEDIGEST_ALGORITHM
protected static final java.lang.String MESSAGEDIGEST_ALGORITHM
- See Also:
- Constant Field Values
-
-
Method Detail
-
afterPropertiesSet
public void afterPropertiesSet() throws org.apache.commons.codec.DecoderException, java.security.NoSuchAlgorithmException- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
org.apache.commons.codec.DecoderExceptionjava.security.NoSuchAlgorithmException
-
getRandom
protected java.security.SecureRandom getRandom()
-
getSignatureKeyBytes
protected byte[] getSignatureKeyBytes()
-
getEncryptionKeyBytes
protected byte[] getEncryptionKeyBytes()
-
encryptData
public java.lang.String encryptData(SecureToken data)
Description copied from interface:SecureTokenServiceEncrypt the SecureToken parameter to a String- Specified by:
encryptDatain interfaceSecureTokenService- Parameters:
data- The unencrypted token data- Returns:
- encrypted token
-
decryptData
public SecureToken decryptData(java.lang.String token)
Description copied from interface:SecureTokenServiceDecrypt the token to a SecureToken.- Specified by:
decryptDatain interfaceSecureTokenService- Parameters:
token- the encrypted token data- Returns:
- decrypted SecureToken
-
decodeHexString
protected byte[] decodeHexString(java.lang.String text) throws org.apache.commons.codec.DecoderException- Throws:
org.apache.commons.codec.DecoderException
-
computePaddingLengths
protected int[] computePaddingLengths()
-
generatePadding
protected byte[] generatePadding(int length)
-
generateSignature
protected byte[] generateSignature(byte[] data, int offset, int length, byte[] signatureKeyBytes) throws java.security.NoSuchAlgorithmException- Throws:
java.security.NoSuchAlgorithmException
-
encrypt
protected java.lang.String encrypt(byte[] plainText, byte[] encryptionKeyBytes) throws java.security.GeneralSecurityException- Throws:
java.security.GeneralSecurityException
-
convert
protected java.lang.String convert(byte[] data)
-
buildSecretKey
protected javax.crypto.spec.SecretKeySpec buildSecretKey(byte[] encryptionKeyBytes)
-
skipPadding
protected void skipPadding(java.io.DataInputStream dataInputStream) throws java.io.IOException- Throws:
java.io.IOException
-
validateSignature
protected boolean validateSignature(byte[] dataBytes, int dataOffset, int dataLength, byte[] signatureBytes, int signatureOffset, byte[] signatureKeyBytes) throws java.security.NoSuchAlgorithmException- Throws:
java.security.NoSuchAlgorithmException
-
arrayEquals
protected boolean arrayEquals(byte[] array1, int offset1, byte[] array2, int offset2, int length)
-
decrypt
protected byte[] decrypt(java.lang.String encryptedText, byte[] encryptionKeyBytes) throws java.security.GeneralSecurityException- Throws:
java.security.GeneralSecurityException
-
createChecksum
protected java.lang.String createChecksum(java.lang.String data) throws java.io.IOException, java.security.NoSuchAlgorithmException- Throws:
java.io.IOExceptionjava.security.NoSuchAlgorithmException
-
getSignatureKeyHex
protected java.lang.String getSignatureKeyHex()
-
setSignatureKeyHex
public void setSignatureKeyHex(java.lang.String signatureKeyHex)
- Parameters:
signatureKeyHex- the signatureKeyHex to set
-
getEncryptionKeyHex
protected java.lang.String getEncryptionKeyHex()
-
setEncryptionKeyHex
public void setEncryptionKeyHex(java.lang.String encryptionKeyHex)
- Parameters:
encryptionKeyHex- the encryptionKeyHex to set
-
-