public class SignatureHelper
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
DEFAULT_MESSAGE_DIGEST_ALGO |
static java.lang.String |
DEFAULT_SIGNATURE_PROVIDER |
| Constructor and Description |
|---|
SignatureHelper() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
containSignature(ScriptType scriptType,
java.io.InputStream inputStream)
Checks the given input stream to see whether it contains signature or not.
|
static byte[] |
convertBase64ToBytes(java.lang.String str)
Converts given
Base64 string to bytes. |
static java.lang.String |
convertBytesToBase64(byte[] bytes)
Converts given bytes in
Base64 form. |
static java.lang.String |
getSignatureInFormat(ScriptType scriptType,
java.lang.String signStr,
java.lang.String certStr,
java.lang.String messageDigestAlgo,
java.lang.String provider)
Converts given signature, messageSigestAlgorithm, provider, and certificate in proper format.
Format for signature block will be as follows: |
static boolean |
isSelfSignedCertificate(java.security.cert.Certificate certificate)
Checks whether provided certificate or certificate attached with is self-signed or not.
|
public static final java.lang.String DEFAULT_MESSAGE_DIGEST_ALGO
public static final java.lang.String DEFAULT_SIGNATURE_PROVIDER
public static java.lang.String convertBytesToBase64(byte[] bytes)
Base64 form.bytes - bytes to be converted to Base64null if input is nullpublic static byte[] convertBase64ToBytes(java.lang.String str)
Base64 string to bytes.str - provide Base64 string to convertnull if input is nullpublic static java.lang.String getSignatureInFormat(ScriptType scriptType, java.lang.String signStr, java.lang.String certStr, java.lang.String messageDigestAlgo, java.lang.String provider) throws ScriptSignatureException
-----BEGIN SIGNATURE-----
hash:
SHA1
provider:
SUN
signature:
signature in Base64 format
certificate/s:
certificate chain in Base64 format (multiple lines)(each line containing 80 chars)
-----END SIGNSTURE-----
scriptType - provide ScriptType instance of stream for scriptsignStr - string representation of signature in Base64 formatcertStr - string representation of certificate chain in Base64 formatmessageDigestAlgo - name the message-digest algorithm using which signature is created. Provide null or empty string or 'default' to set default
algorithmprovider - name the provider used to perform signature. Provide null or empty string to set 'preferred'ScriptSignatureException - when one or more parameter are null or emptypublic static boolean containSignature(ScriptType scriptType, java.io.InputStream inputStream) throws ScriptSignatureException
scriptType - provide ScriptType instance of stream for scriptinputStream - provide InputStream to check for signaturetrue if signature is found or false if signature is not foundScriptSignatureException - when signature format is improperpublic static boolean isSelfSignedCertificate(java.security.cert.Certificate certificate)
throws ScriptSignatureException
certificate - provide certificate to check fortrue if certificate is self-signed or false if certificate is CA signedScriptSignatureException - when certificate is not provided or there is an error while retrieving certificate