Class Utils
- Author:
- hachani
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]canonize(byte[] input) Canonizes an input with inclusive c14n without comments algorithm.static voidcheckHttpCode(int httpCode) Checks for the returned http codestatic byte[]decrypt(byte[] input, SecretKeySpec keySpec) Decrypts the given input according to key spec.static byte[]encrypt(byte[] input, SecretKeySpec keySpec) Encrypts an input with a given key spec.static byte[]static byte[]Generates a random nonce.static DateParses a string datestatic byte[]unzip(byte[] zip) Uncompresses a given byte array input.static byte[]zip(byte[] toZip) Compresses an input of byte array
-
Field Details
-
secureRandom
-
-
Method Details
-
zip
Compresses an input of byte arrayThe 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
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
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
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 encryptkeySpec- the key spec- Returns:
- the encrypted input
- Throws:
EbicsException
-
decrypt
Decrypts the given input according to key spec.- Parameters:
input- the input to decryptkeySpec- the key spec- Returns:
- the decrypted input
- Throws:
EbicsException
-
parse
Parses a string date- Parameters:
date- the given string date- Returns:
- the date value
- Throws:
EbicsException
-
checkHttpCode
Checks for the returned http code- Parameters:
httpCode- the http code- Throws:
EbicsException
-