Class Helper
public abstract class Helper
extends java.lang.Object
Constructor Summary
Constructor and Description |
---|
Helper() |
Method Summary
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) |
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Constructor Detail
Helper
public Helper()
Method Detail
createPrivateKeyFromString
public static java.security.PrivateKey createPrivateKeyFromString(java.lang.String privateKeyString) throws java.security.spec.InvalidKeySpecException, java.security.NoSuchAlgorithmException, java.io.UnsupportedEncodingException
- Parameters:
privateKeyString
- the Base64 encoded private key- Returns:
- a PrivateKey object
- Throws:
java.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.
createPublicKeyFromString
public static java.security.PublicKey createPublicKeyFromString(java.lang.String publicKeyString) throws java.security.spec.InvalidKeySpecException, java.security.NoSuchAlgorithmException, java.io.UnsupportedEncodingException
- Parameters:
publicKeyString
- the Base64 encoded public key- Returns:
- a PublicKey object
- Throws:
java.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.
encryptStringWithPublicKey
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
- Parameters:
data
- the string to be encryptedkey
- the PublicKey object, used for encryption- Returns:
- a base64 encoded representation of the encrypted data
- Throws:
javax.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.
readFile
public static java.lang.String readFile(java.lang.String file) throws java.io.IOException
- Throws:
java.io.IOException
readFile
public static java.lang.String readFile(java.lang.String file, java.lang.String csName) throws java.io.IOException
- Throws:
java.io.IOException
readFile
public static java.lang.String readFile(java.lang.String file, java.nio.charset.Charset cs) throws java.io.IOException
- Throws:
java.io.IOException
readInputStream
public static java.lang.String readInputStream(java.io.InputStream inputStream, java.lang.String csName) throws java.io.IOException
- Throws:
java.io.IOException
readInputStream
public static java.lang.String readInputStream(java.io.InputStream inputStream, java.nio.charset.Charset cs) throws java.io.IOException
- Throws:
java.io.IOException
buildQueryFromParameterMap
public static java.lang.String buildQueryFromParameterMap(java.util.Map<java.lang.String,java.lang.String[]> queryParamsMap) throws java.io.UnsupportedEncodingException
- Parameters:
queryParamsMap
- the query parameter map- Returns:
- a query string
- Throws:
java.io.UnsupportedEncodingException
- If the query string could not be decoded.
concatRequestParams
public static java.lang.String concatRequestParams(java.util.Collection<java.lang.String> params)
- Parameters:
params
- a collection of strings to be concatenated- Returns:
- a string in the form of "abc-xyz-123"
concatRequestParams
public static java.lang.String concatRequestParams(java.util.Map<java.lang.String,java.lang.String[]> params)
- Parameters:
params
- a collection of strings to be concatenated- Returns:
- a string in the form of "abc-xyz-123"
concatStringArray
public static java.lang.String concatStringArray(java.lang.String[] pieces, java.lang.String glue)
- Parameters:
pieces
- an array of strings to be concatenatedglue
- the string used as separator- Returns:
- a string in the form of "abc-xyz-123" if "-" is used as glue
isNumeric
public static boolean isNumeric(java.lang.String str)
- Parameters:
str
- a a string that may be consisted of digits only- Returns:
- true if the string contains only digits, false otherwise
isValidEmail
public static boolean isValidEmail(java.lang.String str)
- Parameters:
str
- a string that may contain an email address- Returns:
- true if the string is a valid email address, false otherwise
isValidOutputFormat
public static boolean isValidOutputFormat(CommunicationFormat format)
- Parameters:
format
- the used communication format- Returns:
- true if the format can be used as an output one
isValidTrnRef
public static boolean isValidTrnRef(java.lang.String str)
- Parameters:
str
- a string containing a transaction reference- Returns:
- true if the string is a valid reference
isValidOrderId
public static boolean isValidOrderId(java.lang.String str)
- Parameters:
str
- a string containing an order id- Returns:
- true if the string is a valid id