public abstract class Helper
extends java.lang.Object
Constructor and Description |
---|
Helper() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
buildQueryFromParameterMap(java.util.Map<java.lang.String,java.lang.String[]> queryParamsMap)
Create a query string from the API request parameter map.
|
static java.lang.String |
concatRequestParams(java.util.Collection<java.lang.String> params)
Concatenates all request parameters, so they can be used for creating
an API request signature, or verifying one.
|
static java.lang.String |
concatRequestParams(java.util.Map<java.lang.String,java.lang.String[]> params)
Concatenates all request parameters, so they can be used for creating
an API request signature, or verifying one.
|
static java.lang.String |
concatStringArray(java.lang.String[] pieces,
java.lang.String glue)
Concatenates the elements of the string array to a single string.
|
static java.security.PrivateKey |
createPrivateKeyFromString(java.lang.String privateKeyString)
Create a PrivateKey object from the provided PEM encoded data.
|
static java.security.PublicKey |
createPublicKeyFromString(java.lang.String publicKeyString)
Create a PublicKey object from the provided PEM encoded data.
|
static java.lang.String |
encryptStringWithPublicKey(java.lang.String data,
java.security.PublicKey key)
Encrypts a string with a provided public key.
|
static boolean |
isNumeric(java.lang.String str)
Checks if a string is numeric (consisted only of digits).
|
static boolean |
isValidEmail(java.lang.String str)
Checks if a string is a valid email address.
|
static boolean |
isValidOrderId(java.lang.String str)
Check if a string is in a valid order id format.
|
static boolean |
isValidOutputFormat(CommunicationFormat format)
Checks if a CommunicationFormat value can be used as an output format (to
send data to the API).
|
static boolean |
isValidTrnRef(java.lang.String str)
Check if a string is in a valid transaction reference format.
|
static java.lang.String |
readFile(java.lang.String file) |
static java.lang.String |
readFile(java.lang.String file,
java.nio.charset.Charset cs) |
static java.lang.String |
readFile(java.lang.String file,
java.lang.String csName) |
static java.lang.String |
readInputStream(java.io.InputStream inputStream,
java.nio.charset.Charset cs) |
static java.lang.String |
readInputStream(java.io.InputStream inputStream,
java.lang.String csName) |
public static java.security.PrivateKey createPrivateKeyFromString(java.lang.String privateKeyString) throws java.security.spec.InvalidKeySpecException, java.security.NoSuchAlgorithmException, java.io.UnsupportedEncodingException
privateKeyString
- the Base64 encoded private keyjava.security.spec.InvalidKeySpecException
- if the private key can not be generatedjava.security.NoSuchAlgorithmException
- If the KeyFactory does not support the needed algorithm.java.io.UnsupportedEncodingException
- If the private key string could not be decoded.public static java.security.PublicKey createPublicKeyFromString(java.lang.String publicKeyString) throws java.security.spec.InvalidKeySpecException, java.security.NoSuchAlgorithmException, java.io.UnsupportedEncodingException
publicKeyString
- the Base64 encoded public keyjava.security.spec.InvalidKeySpecException
- if the public key can not be generatedjava.security.NoSuchAlgorithmException
- If the KeyFactory does not support the needed algorithm.java.io.UnsupportedEncodingException
- If the private key string could not be decoded.public static java.lang.String encryptStringWithPublicKey(java.lang.String data, java.security.PublicKey key) throws javax.crypto.BadPaddingException, javax.crypto.IllegalBlockSizeException, java.security.InvalidKeyException, java.security.NoSuchAlgorithmException, javax.crypto.NoSuchPaddingException, java.io.UnsupportedEncodingException
data
- the string to be encryptedkey
- the PublicKey object, used for encryptionjavax.crypto.BadPaddingException
- if the data is not padded properlyjavax.crypto.IllegalBlockSizeException
- When the length of data provided to a block cipher is incorrect.java.security.InvalidKeyException
- if the public key is invalidjava.security.NoSuchAlgorithmException
- If the KeyFactory does not support the needed algorithm..javax.crypto.NoSuchPaddingException
- when the padding mechanism is not availablejava.io.UnsupportedEncodingException
- If the private key string could not be decoded.public static java.lang.String readFile(java.lang.String file) throws java.io.IOException
java.io.IOException
public static java.lang.String readFile(java.lang.String file, java.lang.String csName) throws java.io.IOException
java.io.IOException
public static java.lang.String readFile(java.lang.String file, java.nio.charset.Charset cs) throws java.io.IOException
java.io.IOException
public static java.lang.String readInputStream(java.io.InputStream inputStream, java.lang.String csName) throws java.io.IOException
java.io.IOException
public static java.lang.String readInputStream(java.io.InputStream inputStream, java.nio.charset.Charset cs) throws java.io.IOException
java.io.IOException
public static java.lang.String buildQueryFromParameterMap(java.util.Map<java.lang.String,java.lang.String[]> queryParamsMap) throws java.io.UnsupportedEncodingException
queryParamsMap
- the query parameter mapjava.io.UnsupportedEncodingException
- If the query string could not be decoded.public static java.lang.String concatRequestParams(java.util.Collection<java.lang.String> params)
params
- a collection of strings to be concatenatedpublic static java.lang.String concatRequestParams(java.util.Map<java.lang.String,java.lang.String[]> params)
params
- a collection of strings to be concatenatedpublic static java.lang.String concatStringArray(java.lang.String[] pieces, java.lang.String glue)
pieces
- an array of strings to be concatenatedglue
- the string used as separatorpublic static boolean isNumeric(java.lang.String str)
str
- a a string that may be consisted of digits onlypublic static boolean isValidEmail(java.lang.String str)
str
- a string that may contain an email addresspublic static boolean isValidOutputFormat(CommunicationFormat format)
format
- the used communication formatpublic static boolean isValidTrnRef(java.lang.String str)
str
- a string containing a transaction referencepublic static boolean isValidOrderId(java.lang.String str)
str
- a string containing an order id