Class SecureKeyBlockBuilder
java.lang.Object
org.jpos.security.SecureKeyBlockBuilder
The builder class to create and parse key block structure.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intSize in characters of the fixed key-block header.protected static final intSize in characters of the MAC trailer when bound with 3-DES.protected static final intSize in characters of the MAC trailer when bound with AES.protected static final intSize in characters of the key-version field.protected static final intSize in characters of the total key-block length field.protected static final intSize in characters of the key-block version byte.protected static final intSize in characters of the key-usage attribute.protected static final intSize in characters of the number-of-optional-headers field.protected static final intSize in characters of an optional header's identifier.protected static final intSize in characters of an optional header's length field.protected static final intSize in characters of the reserved field. -
Method Summary
Modifier and TypeMethodDescriptionbuild(CharSequence data) Parses a key-block string into a populatedSecureKeyBlock.protected static intcalcOptionalHeaderLength(Map<String, String> optHdrs) Calculates the on-wire length contribution of the supplied optional headers.protected intReturns the MAC trailer length appropriate for the given key block's version.static SecureKeyBlockBuilderReturns a newSecureKeyBlockBuilderinstance.parseOptionalHeader(StringReader sr, int numOfBlocks) ParsesnumOfBlocksoptional header blocks fromsrinto a map.protected static charreadChar(StringReader sr) Reads a single character fromsr.protected static StringreadString(StringReader sr, int len) Readslencharacters fromsr.toKeyBlock(SecureKeyBlock skb) Serializes aSecureKeyBlockinto its on-wire string form.with8characterMACVersions(String versions) Configure key block versions with 8 digits key block MAC.
-
Field Details
-
SIZE_KEYBLOCK_VERSION
Size in characters of the key-block version byte.- See Also:
-
SIZE_KEYBLOCK_LENGTH
Size in characters of the total key-block length field.- See Also:
-
SIZE_KEYUSAGE
-
SIZE_KEY_VERSION
-
SIZE_NUMOFOPTHDR
Size in characters of the number-of-optional-headers field.- See Also:
-
SIZE_RESERVED
-
SIZE_HEADER
-
SIZE_OPTHDR_ID
Size in characters of an optional header's identifier.- See Also:
-
SIZE_OPTHDR_LENGTH
Size in characters of an optional header's length field.- See Also:
-
SIZE_HEADER_3DES
Size in characters of the MAC trailer when bound with 3-DES.- See Also:
-
SIZE_HEADER_AES
Size in characters of the MAC trailer when bound with AES.- See Also:
-
-
Method Details
-
newBuilder
Returns a newSecureKeyBlockBuilderinstance.- 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
Returns the MAC trailer length appropriate for the given key block's version.- Parameters:
skb- the key block being inspected- Returns:
SIZE_HEADER_3DESfor 8-character MAC versions,SIZE_HEADER_AESotherwise
-
readString
Readslencharacters fromsr.- Parameters:
sr- source readerlen- number of characters to read- Returns:
- the characters read, as a
String - Throws:
IllegalArgumentException- if reading fails
-
readChar
Reads a single character fromsr.- Parameters:
sr- source reader- Returns:
- the character read
- Throws:
IllegalArgumentException- if reading fails
-
parseOptionalHeader
ParsesnumOfBlocksoptional header blocks fromsrinto a map.- Parameters:
sr- source reader, positioned at the first optional headernumOfBlocks- number of optional headers to consume- Returns:
- a map from header identifier to header value, in iteration order
-
calcOptionalHeaderLength
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 populatedSecureKeyBlock.- Parameters:
data- raw key-block characters (header, optional headers, encrypted key, MAC)- Returns:
- the parsed key block
- Throws:
IllegalArgumentException- ifdatais shorter than the fixed header or otherwise malformed
-
toKeyBlock
Serializes aSecureKeyBlockinto its on-wire string form.- Parameters:
skb- the key block to serialize- Returns:
- the encoded key-block string (header + optional headers + encrypted key + MAC)
-