Class Utils

java.lang.Object
org.kopi.ebics.utils.Utils

public final class Utils extends Object
Some utilities for EBICS request creation and reception
Author:
hachani
  • Field Details

    • secureRandom

      public static final SecureRandom secureRandom
  • Method Details

    • zip

      public static byte[] zip(byte[] toZip) throws EbicsException
      Compresses an input of byte array

      The Decompression is ensured via Universal compression algorithm (RFC 1950, RFC 1951) As specified in the EBICS specification (16 Appendix: Standards and references)

      Parameters:
      toZip - the input to be compressed
      Returns:
      the compressed input data
      Throws:
      EbicsException - compression failed
    • generateNonce

      public static byte[] generateNonce()
      Generates a random nonce.

      EBICS Specification 2.4.2 - 11.6 Generation of the transaction IDs:

      Transaction IDs are cryptographically-strong random numbers with a length of 128 bits. This means that the likelihood of any two bank systems using the same transaction ID at the same time is sufficiently small.

      Transaction IDs are generated by cryptographic pseudo-random number generators (PRNG) that have been initialized with a real random number (seed). The entropy of the seed should be at least 100 bits.

      Returns:
      a random nonce.
    • generateKey

      public static byte[] generateKey()
    • unzip

      public static byte[] unzip(byte[] zip) throws EbicsException
      Uncompresses a given byte array input. The Decompression is ensured via Universal compression algorithm (RFC 1950, RFC 1951) As specified in the EBICS specification (16 Appendix: Standards and references)
      Parameters:
      zip - the zipped input.
      Returns:
      the uncompressed data.
      Throws:
      EbicsException
    • canonize

      public static byte[] canonize(byte[] input) throws EbicsException
      Canonizes an input with inclusive c14n without comments algorithm.

      EBICS Specification 2.4.2 - 5.5.1.1.1 EBICS messages in transaction initialization:

      The identification and authentication signature includes all XML elements of the EBICS request whose attribute value for @authenticate is equal to “true”. The definition of the XML schema “ebics_request.xsd“ guarantees that the value of the attribute @authenticate is equal to “true” for precisely those elements that also need to be signed.

      Thus, All the Elements with the attribute authenticate = true and their sub elements are considered for the canonization process.

      Parameters:
      input - the byte array XML input.
      Returns:
      the canonized form of the given XML
      Throws:
      EbicsException
    • encrypt

      public static byte[] encrypt(byte[] input, SecretKeySpec keySpec) throws EbicsException
      Encrypts an input with a given key spec.

      EBICS Specification 2.4.2 - 15.1 Workflows at the sender’s end:

      Preparation for DEK encryption

      The 128 bit DEK that is interpreted as a natural number is filled out with null bits to 768 bits in front of the highest-value bit. The result is called PDEK.

      Encryption of the secret DES key

      PDEK is then encrypted with the recipient’s public key of the RSA key system and is then expanded with leading null bits to 1024 bits.

      The result is called EDEK. It must be ensured that EDEK is not equal to DEK.

      Encryption of the messages

      Padding of the message:

      The method Padding with Octets in accordance with ANSI X9.23 is used for padding the message, i.e. in all cases, data is appended to the message that is to be encrypted.

      Application of the encryption algorithm:

      The message is encrypted in CBC mode in accordance with ANSI X3.106 with the secret key DEK according to the 2-key triple DES process as specified in ANSI X3.92-1981.

      In doing this, the following initialization value “ICV” is used: X ‘00 00 00 00 00 00 00 00’.

      Parameters:
      input - the input to encrypt
      keySpec - the key spec
      Returns:
      the encrypted input
      Throws:
      EbicsException
    • decrypt

      public static byte[] decrypt(byte[] input, SecretKeySpec keySpec) throws EbicsException
      Decrypts the given input according to key spec.
      Parameters:
      input - the input to decrypt
      keySpec - the key spec
      Returns:
      the decrypted input
      Throws:
      EbicsException
    • parse

      public static Date parse(String date) throws EbicsException
      Parses a string date
      Parameters:
      date - the given string date
      Returns:
      the date value
      Throws:
      EbicsException
    • checkHttpCode

      public static void checkHttpCode(int httpCode) throws EbicsException
      Checks for the returned http code
      Parameters:
      httpCode - the http code
      Throws:
      EbicsException