public class SignatureHelper extends Object
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_MESSAGE_DIGEST_ALGO |
static String |
DEFAULT_SIGNATURE_PROVIDER |
Constructor and Description |
---|
SignatureHelper() |
Modifier and Type | Method and Description |
---|---|
static boolean |
containSignature(ScriptType scriptType,
InputStream inputStream)
Checks the given input stream to see whether it contains signature or not.
|
static byte[] |
convertBase64ToBytes(String str)
Converts given
Base64 string to bytes. |
static String |
convertBytesToBase64(byte[] bytes)
Converts given bytes in
Base64 form. |
static String |
getSignatureInFormat(ScriptType scriptType,
String signStr,
String certStr,
String messageDigestAlgo,
String provider)
Converts given signature, messageSigestAlgorithm, provider, and certificate in proper format.
Format for signature block will be as follows: |
static boolean |
isSelfSignedCertificate(Certificate certificate)
Checks whether provided certificate or certificate attached with is self-signed or not.
|
public static final String DEFAULT_MESSAGE_DIGEST_ALGO
public static final String DEFAULT_SIGNATURE_PROVIDER
public static String convertBytesToBase64(byte[] bytes)
Base64
form.bytes
- bytes to be converted to Base64null
if input is null
public static byte[] convertBase64ToBytes(String str)
Base64
string to bytes.str
- provide Base64
string to convertnull
if input is nullpublic static String getSignatureInFormat(ScriptType scriptType, String signStr, String certStr, String messageDigestAlgo, 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, 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(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