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 String
DEFAULT_MESSAGE_DIGEST_ALGO
static String
DEFAULT_SIGNATURE_PROVIDER
-
Constructor Summary
Constructors Constructor Description SignatureHelper()
-
Method Summary
Modifier and Type Method 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 givenBase64
string to bytes.static String
convertBytesToBase64(byte[] bytes)
Converts given bytes inBase64
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.
-
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 inBase64
form.- Parameters:
bytes
- bytes to be converted to Base64- Returns:
- String representation of bytes in Base64 form or
null
if input isnull
-
convertBase64ToBytes
Converts givenBase64
string to bytes.- Parameters:
str
- provideBase64
string to convert- Returns:
- bytes is conversion is successful and
null
if 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 inBase64
format
certificate/s:
certificate chain inBase64
format (multiple lines)(each line containing 80 chars)
-----END SIGNSTURE-----
- Parameters:
scriptType
- provideScriptType
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. Providenull
or empty string or 'default' to set default algorithmprovider
- name the provider used to perform signature. Providenull
or empty string to set 'preferred'- Returns:
- string representation of signature block in proper format
- Throws:
ScriptSignatureException
- when one or more parameter arenull
or 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
- provideScriptType
instance of stream for scriptinputStream
- provideInputStream
to check for signature- Returns:
true
if signature is found orfalse
if 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:
true
if certificate is self-signed orfalse
if certificate is CA signed- Throws:
ScriptSignatureException
- when certificate is not provided or there is an error while retrieving certificate
-