Class SecureKeyBlockBuilder

java.lang.Object
org.jpos.security.SecureKeyBlockBuilder

public class SecureKeyBlockBuilder extends Object
The builder class to create and parse key block structure.
  • Field Details

  • Method Details

    • newBuilder

      Returns a new SecureKeyBlockBuilder instance.
      Returns:
      a fresh builder
    • with8characterMACVersions

      Configure key block versions with 8 digits key block MAC.

      Default 8 digits (4 bytes) key block MAC versions are:

      • 'A' TR-31:2005 Key block protected using the Key Variant Binding Method
      • 'B' TR-31:2010 Key block protected using the Key Derivation Binding Method
      • 'C' TR-31:2010 Key block protected using the Key Variant Binding Method
      • '0' Proprietary Key block protected using the 3-DES key
      Parameters:
      versions - the string with versions characters
      Returns:
      This builder instance
    • getMACLength

      protected int getMACLength(SecureKeyBlock skb)
      Returns the MAC trailer length appropriate for the given key block's version.
      Parameters:
      skb - the key block being inspected
      Returns:
      SIZE_HEADER_3DES for 8-character MAC versions, SIZE_HEADER_AES otherwise
    • readString

      protected static String readString(StringReader sr, int len)
      Reads len characters from sr.
      Parameters:
      sr - source reader
      len - number of characters to read
      Returns:
      the characters read, as a String
      Throws:
      IllegalArgumentException - if reading fails
    • readChar

      protected static char readChar(StringReader sr)
      Reads a single character from sr.
      Parameters:
      sr - source reader
      Returns:
      the character read
      Throws:
      IllegalArgumentException - if reading fails
    • parseOptionalHeader

      protected static Map<String,String> parseOptionalHeader(StringReader sr, int numOfBlocks)
      Parses numOfBlocks optional header blocks from sr into a map.
      Parameters:
      sr - source reader, positioned at the first optional header
      numOfBlocks - number of optional headers to consume
      Returns:
      a map from header identifier to header value, in iteration order
    • calcOptionalHeaderLength

      protected static int calcOptionalHeaderLength(Map<String,String> optHdrs)
      Calculates the on-wire length contribution of the supplied optional headers.
      Parameters:
      optHdrs - optional headers
      Returns:
      total characters required to encode them, including id and length prefixes
    • build

      Parses a key-block string into a populated SecureKeyBlock.
      Parameters:
      data - raw key-block characters (header, optional headers, encrypted key, MAC)
      Returns:
      the parsed key block
      Throws:
      IllegalArgumentException - if data is shorter than the fixed header or otherwise malformed
    • toKeyBlock

      Serializes a SecureKeyBlock into its on-wire string form.
      Parameters:
      skb - the key block to serialize
      Returns:
      the encoded key-block string (header + optional headers + encrypted key + MAC)