Class ValueLinkApi
java.lang.Object
org.apache.ofbiz.accounting.thirdparty.valuelink.ValueLinkApi
ValueLinkApi - Implementation of ValueLink Encryption and Transport
-
Constructor Summary
ModifierConstructorDescriptionprotected
protected
ValueLinkApi
(Delegator delegator, Properties props) -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
copyBytes
(byte[] source, byte[] target, int position) Copies a byte[] into another byte[] starting at a specific positionCreate a set of public/private keys using ValueLinks defined parametersprotected byte[]
cryptoViaKek
(byte[] content, int mode) actual kek encryption/decryption codedecryptPin
(String pin) Decrypt an encrypted pin using the configured keysbyte[]
decryptViaKek
(byte[] content) Ue the KEK to decrypt a valueencryptPin
(String pin) Encrypt the defined pin using the configured keysbyte[]
encryptViaKek
(byte[] content) Use the KEK to encrypt a value usually the MWKbyte[]
generateKek
(PrivateKey privateKey) Generate a key exchange key for use in encrypting the mwkbyte[]
Generate a new MWKbyte[]
generateMwk
(byte[] desBytes) Generate a new MWKbyte[]
generateMwk
(SecretKey mwkdes3) Generate a new MWKReturns a BigDecimal from a ValueLink formatted amount StringgetAmount
(BigDecimal amount) Returns a ValueLink formatted amount Stringstatic byte[]
getByteRange
(byte[] bytes, int offset, int length) Returns a new byte[] from the offset of the defined byte[] with a specific number of bytesprotected static Cipher
getCipher
(Key key, int mode, IvParameterSpec iv) getCurrency
(String currency) Gets currency.Returns a date string formatted as directed by ValueLinkprotected SecretKey
getDesEdeKey
(byte[] rawKey) Gets des ede key.protected DHParameterSpec
using the prime and generator provided by valuelink; create a parameter objectGets the cached value object for this merchant's keysgetInitialRequestMap
(Map<String, Object> context) Creates a Map of initial request values (MerchID, AltMerchNo, Modes, MerchTime, TermTxnNo, EncryptID) Note: For 2010 (assign working key) transaction, the EncryptID will need to be adjustedstatic ValueLinkApi
getInstance
(Delegator delegator, Properties props) Obtain an instance of the ValueLinkApi; this method will always return an existing reference if one is availablestatic ValueLinkApi
getInstance
(Delegator delegator, Properties props, boolean reload) Obtain an instance of the ValueLinkApiprotected byte[]
getKek()
Get kek byte [ ].protected SecretKey
Gets kek key.protected byte[]
getMwk()
Get mwk byte [ ].protected SecretKey
Gets mwk key.protected byte[]
getPinCheckSum
(byte[] pinBytes) Get pin check sum byte [ ].Get merchant Private Keyprotected byte[]
Get private key bytes byte [ ].protected byte[]
getRandomBytes
(int length) Get random bytes byte [ ].Get a public key object for the ValueLink supplied public keyReturns the current working key indexoutputKeyCreation
(boolean kekOnly, String kekTest) Output the creation of public/private keys + KEK to the console for manual database update @parseResponse
(String response) Parse response map.void
reload()
Reloads the keys in the object cache; use this when re-creating keysTransmit a request to ValueLinkTransmit a request to ValueLink
-
Constructor Details
-
ValueLinkApi
protected ValueLinkApi() -
ValueLinkApi
-
-
Method Details
-
getInstance
Obtain an instance of the ValueLinkApi- Parameters:
delegator
- Delegator used to query the encryption keysprops
- Properties to use for the Api (usually payment.properties)reload
- When true, will replace an existing instance in the cache and reload all properties- Returns:
- ValueLinkApi reference
-
getInstance
Obtain an instance of the ValueLinkApi; this method will always return an existing reference if one is available- Parameters:
delegator
- Delegator used to query the encryption keysprops
- Properties to use for the Api (usually payment.properties)- Returns:
- Obtain an instance of the ValueLinkApi
-
encryptPin
Encrypt the defined pin using the configured keys- Parameters:
pin
- Plain text String of the pin- Returns:
- Hex String of the encrypted pin (EAN) for transmission to ValueLink
-
decryptPin
Decrypt an encrypted pin using the configured keys- Parameters:
pin
- Hex String of the encrypted pin (EAN)- Returns:
- Plain text String of the pin @
-
send
Transmit a request to ValueLink- Parameters:
request
- Map of request parameters- Returns:
- Map of response parameters
- Throws:
HttpClientException
-
send
Transmit a request to ValueLink- Parameters:
url
- override URL from what is defined in the propertiesrequest
- request Map of request parameters- Returns:
- Map of response parameters
- Throws:
HttpClientException
-
outputKeyCreation
Output the creation of public/private keys + KEK to the console for manual database update @ -
createKeys
public KeyPair createKeys() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeySpecExceptionCreate a set of public/private keys using ValueLinks defined parameters- Returns:
- KeyPair object containing both public and private keys
- Throws:
NoSuchAlgorithmException
InvalidAlgorithmParameterException
InvalidKeySpecException
-
generateKek
public byte[] generateKek(PrivateKey privateKey) throws NoSuchAlgorithmException, InvalidKeySpecException, InvalidKeyException Generate a key exchange key for use in encrypting the mwk- Parameters:
privateKey
- The private key for the merchant- Returns:
- byte array containing the kek
- Throws:
NoSuchAlgorithmException
InvalidKeySpecException
InvalidKeyException
-
getValueLinkPublicKey
Get a public key object for the ValueLink supplied public key- Returns:
- PublicKey object of ValueLinks's public key
- Throws:
NoSuchAlgorithmException
InvalidKeySpecException
-
getPrivateKey
Get merchant Private Key- Returns:
- PrivateKey object for the merchant
- Throws:
InvalidKeySpecException
NoSuchAlgorithmException
-
generateMwk
public byte[] generateMwk()Generate a new MWK- Returns:
- Hex String of the new encrypted MWK ready for transmission to ValueLink @
-
generateMwk
public byte[] generateMwk(byte[] desBytes) Generate a new MWK- Parameters:
desBytes
- byte array of the DES key (24 bytes)- Returns:
- Hex String of the new encrypted MWK ready for transmission to ValueLink @
-
generateMwk
Generate a new MWK- Parameters:
mwkdes3
- pre-generated DES3 SecretKey- Returns:
- Hex String of the new encrypted MWK ready for transmission to ValueLink @
-
encryptViaKek
public byte[] encryptViaKek(byte[] content) Use the KEK to encrypt a value usually the MWK- Parameters:
content
- byte array to encrypt- Returns:
- encrypted byte array
-
decryptViaKek
public byte[] decryptViaKek(byte[] content) Ue the KEK to decrypt a value- Parameters:
content
- byte array to decrypt- Returns:
- decrypted byte array
-
getDateString
Returns a date string formatted as directed by ValueLink- Returns:
- ValueLink formatted date String
-
getWorkingKeyIndex
Returns the current working key index- Returns:
- Long number of the current working key index
-
getAmount
Returns a ValueLink formatted amount String- Parameters:
amount
- BigDecimal value to format- Returns:
- Formatted String
-
getAmount
Returns a BigDecimal from a ValueLink formatted amount String- Parameters:
amount
- The ValueLink formatted amount String- Returns:
- BigDecimal object
-
getCurrency
Gets currency.- Parameters:
currency
- the currency- Returns:
- the currency
-
getInitialRequestMap
Creates a Map of initial request values (MerchID, AltMerchNo, Modes, MerchTime, TermTxnNo, EncryptID) Note: For 2010 (assign working key) transaction, the EncryptID will need to be adjusted- Returns:
- Map containing the inital request values
-
getGenericValue
Gets the cached value object for this merchant's keys- Returns:
- Cached GenericValue object
-
reload
public void reload()Reloads the keys in the object cache; use this when re-creating keys -
getDHParameterSpec
using the prime and generator provided by valuelink; create a parameter object -
cryptoViaKek
actual kek encryption/decryption code- Throws:
GeneralException
-
getCipher
- Throws:
GeneralException
-
getPinCheckSum
protected byte[] getPinCheckSum(byte[] pinBytes) Get pin check sum byte [ ].- Parameters:
pinBytes
- the pin bytes- Returns:
- the byte [ ]
-
getRandomBytes
protected byte[] getRandomBytes(int length) Get random bytes byte [ ].- Parameters:
length
- the length- Returns:
- the byte [ ]
-
getMwkKey
Gets mwk key.- Returns:
- the mwk key
-
getKekKey
Gets kek key.- Returns:
- the kek key
-
getDesEdeKey
Gets des ede key.- Parameters:
rawKey
- the raw key- Returns:
- the des ede key
-
getMwk
protected byte[] getMwk()Get mwk byte [ ].- Returns:
- the byte [ ]
-
getKek
protected byte[] getKek()Get kek byte [ ].- Returns:
- the byte [ ]
-
getPrivateKeyBytes
protected byte[] getPrivateKeyBytes()Get private key bytes byte [ ].- Returns:
- the byte [ ]
-
parseResponse
Parse response map.- Parameters:
response
- the response- Returns:
- the map
-
getByteRange
public static byte[] getByteRange(byte[] bytes, int offset, int length) Returns a new byte[] from the offset of the defined byte[] with a specific number of bytes- Parameters:
bytes
- The byte[] to extract fromoffset
- The starting postitionlength
- The number of bytes to copy- Returns:
- a new byte[]
-
copyBytes
public static byte[] copyBytes(byte[] source, byte[] target, int position) Copies a byte[] into another byte[] starting at a specific position- Parameters:
source
- byte[] to copy fromtarget
- byte[] coping intoposition
- the position on target where source will be copied to- Returns:
- a new byte[]
-