public class DefaultCouponCodeCipherTextGenerationStrategy extends AbstractCouponCodeGenerationStrategy implements CouponCodeCipherTextGenerationStrategy
| Constructor and Description |
|---|
DefaultCouponCodeCipherTextGenerationStrategy() |
| Modifier and Type | Method and Description |
|---|---|
void |
afterPropertiesSet() |
protected void |
checkLength(int length)
checks that the given length is supported (2,4,6,8,12,16,20,24,28,32).
|
protected void |
checkLength(String clearText)
checks that the given clearText is of allowed length (such that
clearText.getBytes().length <= 16)) |
protected String |
constructCipherText(MultiCodeCouponModel coupon,
int[] cipherTextInput)
constructs the ciphertext based on the given input byte array.
|
protected byte[] |
decodeSignature(MultiCodeCouponModel coupon)
decodes the coupon.signature via
Base64.decode(String). |
protected byte[] |
encrypt(MultiCodeCouponModel coupon,
String clearText)
encrypts the given cleartext using the signature defined on the coupon.
|
String |
generateCipherText(MultiCodeCouponModel coupon,
String clearText,
int length)
returns the generated cipher-text part of the coupon code for the given clearText with the given length
|
protected Cipher |
getCipher(MultiCodeCouponModel coupon) |
protected ConfigurationService |
getConfigurationService() |
protected Map<Integer,Integer> |
getLengthToIntMapping() |
void |
setConfigurationService(ConfigurationService configurationService) |
void |
setLengthToIntMapping(Map<Integer,Integer> lengthToIntMapping)
This mapping defines how many input
int values are needed for a given length of 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.
|
createIntFromTwoCharactersString, createTwoCharactersFromByte, pickCharacter, pickIntpublic DefaultCouponCodeCipherTextGenerationStrategy()
public void afterPropertiesSet()
public String generateCipherText(MultiCodeCouponModel coupon, String clearText, int length)
CouponCodeCipherTextGenerationStrategygenerateCipherText in interface CouponCodeCipherTextGenerationStrategyprotected byte[] encrypt(MultiCodeCouponModel coupon, String clearText)
protected final String constructCipherText(MultiCodeCouponModel coupon, int[] cipherTextInput)
protected int[] transform(byte[] encryptedData,
int length)
protected Cipher getCipher(MultiCodeCouponModel coupon) throws NoSuchAlgorithmException
NoSuchAlgorithmExceptionprotected byte[] decodeSignature(MultiCodeCouponModel coupon)
Base64.decode(String).protected void checkLength(int length)
protected void checkLength(String clearText)
clearText.getBytes().length <= 16))protected ConfigurationService getConfigurationService()
public void setConfigurationService(ConfigurationService configurationService)
public void setLengthToIntMapping(Map<Integer,Integer> lengthToIntMapping)
int values are needed for a given length of 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
Copyright © 2017 SAP SE. All Rights Reserved.