Package org.eclipse.ease.sign
Class SignatureHelper
java.lang.Object
org.eclipse.ease.sign.SignatureHelper
public class SignatureHelper extends Object
Class containing helper methods for conversion of format and appending signature to file.
-
Field Summary
Fields Modifier and Type Field Description static StringDEFAULT_MESSAGE_DIGEST_ALGOstatic StringDEFAULT_SIGNATURE_PROVIDER -
Constructor Summary
Constructors Constructor Description SignatureHelper() -
Method Summary
Modifier and Type Method Description static booleancontainSignature(ScriptType scriptType, InputStream inputStream)Checks the given input stream to see whether it contains signature or not.static byte[]convertBase64ToBytes(String str)Converts givenBase64string to bytes.static StringconvertBytesToBase64(byte[] bytes)Converts given bytes inBase64form.static StringgetSignatureInFormat(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 booleanisSelfSignedCertificate(Certificate certificate)Checks whether provided certificate or certificate attached with is self-signed or not.
-
Field Details
-
DEFAULT_MESSAGE_DIGEST_ALGO
- See Also:
- Constant Field Values
-
DEFAULT_SIGNATURE_PROVIDER
- See Also:
- Constant Field Values
-
-
Constructor Details
-
SignatureHelper
public SignatureHelper()
-
-
Method Details
-
convertBytesToBase64
Converts given bytes inBase64form.- Parameters:
bytes- bytes to be converted to Base64- Returns:
- String representation of bytes in Base64 form or
nullif input isnull
-
convertBase64ToBytes
Converts givenBase64string to bytes.- Parameters:
str- provideBase64string to convert- Returns:
- bytes is conversion is successful and
nullif input is null
-
getSignatureInFormat
public static String getSignatureInFormat(ScriptType scriptType, String signStr, String certStr, String messageDigestAlgo, String provider) throws ScriptSignatureExceptionConverts given signature, messageSigestAlgorithm, provider, and certificate in proper format.
Format for signature block will be as follows:-----BEGIN SIGNATURE-----
hash:
SHA1
provider:
SUN
signature:
signature inBase64format
certificate/s:
certificate chain inBase64format (multiple lines)(each line containing 80 chars)
-----END SIGNSTURE-----
- Parameters:
scriptType- provideScriptTypeinstance 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. Providenullor empty string or 'default' to set default algorithmprovider- name the provider used to perform signature. Providenullor empty string to set 'preferred'- Returns:
- string representation of signature block in proper format
- Throws:
ScriptSignatureException- when one or more parameter arenullor empty
-
containSignature
public static boolean containSignature(ScriptType scriptType, InputStream inputStream) throws ScriptSignatureExceptionChecks the given input stream to see whether it contains signature or not.- Parameters:
scriptType- provideScriptTypeinstance of stream for scriptinputStream- provideInputStreamto check for signature- Returns:
trueif signature is found orfalseif signature is not found- Throws:
ScriptSignatureException- when signature format is improper
-
isSelfSignedCertificate
public static boolean isSelfSignedCertificate(Certificate certificate) throws ScriptSignatureExceptionChecks whether provided certificate or certificate attached with is self-signed or not.- Parameters:
certificate- provide certificate to check for- Returns:
trueif certificate is self-signed orfalseif certificate is CA signed- Throws:
ScriptSignatureException- when certificate is not provided or there is an error while retrieving certificate
-