Class ValueLinkApi


  • public class ValueLinkApi
    extends Object
    ValueLinkApi - Implementation of ValueLink Encryption and Transport
    • Constructor Detail

      • ValueLinkApi

        protected ValueLinkApi()
    • Method Detail

      • getInstance

        public static ValueLinkApi getInstance​(Delegator delegator,
                                               Properties props,
                                               boolean reload)
        Obtain an instance of the ValueLinkApi
        Parameters:
        delegator - Delegator used to query the encryption keys
        props - 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

        public static ValueLinkApi getInstance​(Delegator delegator,
                                               Properties props)
        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 keys
        props - Properties to use for the Api (usually payment.properties)
        Returns:
        Obtain an instance of the ValueLinkApi
      • encryptPin

        public String encryptPin​(String pin)
        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

        public String decryptPin​(String pin)
        Decrypt an encrypted pin using the configured keys
        Parameters:
        pin - Hex String of the encrypted pin (EAN)
        Returns:
        Plain text String of the pin @
      • outputKeyCreation

        public StringBuffer outputKeyCreation​(boolean kekOnly,
                                              String kekTest)
        Output the creation of public/private keys + KEK to the console for manual database update @
      • 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

        public byte[] generateMwk​(SecretKey mwkdes3)
        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

        public String getDateString()
        Returns a date string formatted as directed by ValueLink
        Returns:
        ValueLink formatted date String
      • getWorkingKeyIndex

        public Long getWorkingKeyIndex()
        Returns the current working key index
        Returns:
        Long number of the current working key index
      • getAmount

        public String getAmount​(BigDecimal amount)
        Returns a ValueLink formatted amount String
        Parameters:
        amount - BigDecimal value to format
        Returns:
        Formatted String
      • getAmount

        public BigDecimal getAmount​(String amount)
        Returns a BigDecimal from a ValueLink formatted amount String
        Parameters:
        amount - The ValueLink formatted amount String
        Returns:
        BigDecimal object
      • getCurrency

        public String getCurrency​(String currency)
      • getInitialRequestMap

        public Map<String,​Object> getInitialRequestMap​(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 adjusted
        Returns:
        Map containing the inital request values
      • getGenericValue

        public GenericValue 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
      • cryptoViaKek

        protected byte[] cryptoViaKek​(byte[] content,
                                      int mode)
                               throws GeneralException
        actual kek encryption/decryption code
        Throws:
        GeneralException
      • getPinCheckSum

        protected byte[] getPinCheckSum​(byte[] pinBytes)
      • getRandomBytes

        protected byte[] getRandomBytes​(int length)
      • getMwkKey

        protected SecretKey getMwkKey()
      • getKekKey

        protected SecretKey getKekKey()
      • getDesEdeKey

        protected SecretKey getDesEdeKey​(byte[] rawKey)
      • getMwk

        protected byte[] getMwk()
      • getKek

        protected byte[] getKek()
      • getPrivateKeyBytes

        protected byte[] getPrivateKeyBytes()
      • 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 from
        offset - The starting postition
        length - 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 from
        target - byte[] coping into
        position - the position on target where source will be copied to
        Returns:
        a new byte[]