Class DefaultCouponCodeCipherTextGenerationStrategy
- java.lang.Object
-
- de.hybris.platform.couponservices.couponcodegeneration.impl.AbstractCouponCodeGenerationStrategy
-
- de.hybris.platform.couponservices.couponcodegeneration.impl.DefaultCouponCodeCipherTextGenerationStrategy
-
- All Implemented Interfaces:
CouponCodeCipherTextGenerationStrategy,org.springframework.beans.factory.InitializingBean
public class DefaultCouponCodeCipherTextGenerationStrategy extends AbstractCouponCodeGenerationStrategy implements CouponCodeCipherTextGenerationStrategy, org.springframework.beans.factory.InitializingBean
-
-
Constructor Summary
Constructors Constructor Description DefaultCouponCodeCipherTextGenerationStrategy()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterPropertiesSet()protected voidcheckLength(int length)checks that the given length is supported (2,4,6,8,12,16,20,24,28,32).protected voidcheckLength(java.lang.String clearText)checks that the given clearText is of allowed length (such thatclearText.getBytes().length <= 16))protected java.lang.StringconstructCipherText(MultiCodeCouponModel coupon, int[] cipherTextInput)constructs the ciphertext based on the given input byte array.protected byte[]decodeSignature(MultiCodeCouponModel coupon)decodes the coupon.signature viaBase64.decode(String).protected byte[]encrypt(MultiCodeCouponModel coupon, java.lang.String clearText)encrypts the given cleartext using the signature defined on the coupon.java.lang.StringgenerateCipherText(MultiCodeCouponModel coupon, java.lang.String clearText, int length)returns the generated cipher-text part of the coupon code for the given clearText with the given lengthprotected javax.crypto.CiphergetCipher(MultiCodeCouponModel coupon)protected ConfigurationServicegetConfigurationService()protected java.util.Map<java.lang.Integer,java.lang.Integer>getLengthToIntMapping()voidsetConfigurationService(ConfigurationService configurationService)voidsetLengthToIntMapping(java.util.Map<java.lang.Integer,java.lang.Integer> lengthToIntMapping)This mapping defines how many inputintvalues are needed for a givenlengthof cipher-text.protected int[]transform(byte[] encryptedData, int length)transforms the given input of 16-byte array into an array of ints of specified length.-
Methods inherited from class de.hybris.platform.couponservices.couponcodegeneration.impl.AbstractCouponCodeGenerationStrategy
createIntFromTwoCharactersString, createTwoCharactersFromByte, pickCharacter, pickInt
-
-
-
-
Method Detail
-
afterPropertiesSet
public void afterPropertiesSet()
- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean
-
generateCipherText
public java.lang.String generateCipherText(MultiCodeCouponModel coupon, java.lang.String clearText, int length)
Description copied from interface:CouponCodeCipherTextGenerationStrategyreturns the generated cipher-text part of the coupon code for the given clearText with the given length- Specified by:
generateCipherTextin interfaceCouponCodeCipherTextGenerationStrategy
-
encrypt
protected byte[] encrypt(MultiCodeCouponModel coupon, java.lang.String clearText)
encrypts the given cleartext using the signature defined on the coupon.
-
constructCipherText
protected final java.lang.String constructCipherText(MultiCodeCouponModel coupon, int[] cipherTextInput)
constructs the ciphertext based on the given input byte array.
-
transform
protected int[] transform(byte[] encryptedData, int length)transforms the given input of 16-byte array into an array of ints of specified length. Each of the resulting ints is composed of three (unsigned) bytes (using the lower 24 bits of the int).
-
getCipher
protected javax.crypto.Cipher getCipher(MultiCodeCouponModel coupon) throws java.security.NoSuchAlgorithmException
- Throws:
java.security.NoSuchAlgorithmException
-
decodeSignature
protected byte[] decodeSignature(MultiCodeCouponModel coupon)
decodes the coupon.signature viaBase64.decode(String).
-
checkLength
protected void checkLength(int length)
checks that the given length is supported (2,4,6,8,12,16,20,24,28,32).
-
checkLength
protected void checkLength(java.lang.String clearText)
checks that the given clearText is of allowed length (such thatclearText.getBytes().length <= 16))
-
getConfigurationService
protected ConfigurationService getConfigurationService()
-
setConfigurationService
public void setConfigurationService(ConfigurationService configurationService)
-
getLengthToIntMapping
protected java.util.Map<java.lang.Integer,java.lang.Integer> getLengthToIntMapping()
-
setLengthToIntMapping
public void setLengthToIntMapping(java.util.Map<java.lang.Integer,java.lang.Integer> lengthToIntMapping)
This mapping defines how many inputintvalues are needed for a givenlengthof cipher-text. For each 2 characters of ciphertext one input int is needed. Only the lower three bytes of an int are used. Therefore, the default mapping is:4 characters -> 2 bytes -> 1 int 6 characters -> 3 bytes -> 1 int 8 characters -> 4 bytes -> 2 ints 12 characters -> 6 bytes -> 2 ints 16 characters -> 8 bytes -> 3 ints 20 characters -> 10 bytes -> 4 ints 28 characters -> 14 bytes -> 5 ints 32 characters -> 16 bytes -> 6 ints
-
-