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 Details

  • Constructor Details

    • SignatureHelper

      public SignatureHelper()
  • Method Details

    • convertBytesToBase64

      public static String convertBytesToBase64​(byte[] bytes)
      Converts given bytes in Base64 form.
      Parameters:
      bytes - bytes to be converted to Base64
      Returns:
      String representation of bytes in Base64 form or null if input is null
    • convertBase64ToBytes

      public static byte[] convertBase64ToBytes​(String str)
      Converts given Base64 string to bytes.
      Parameters:
      str - provide Base64 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 ScriptSignatureException
      Converts 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 in Base64 format

      certificate/s:
      certificate chain in Base64 format (multiple lines)(each line containing 80 chars)

      -----END SIGNSTURE-----

      Parameters:
      scriptType - provide ScriptType instance of stream for script
      signStr - string representation of signature in Base64 format
      certStr - string representation of certificate chain in Base64 format
      messageDigestAlgo - name the message-digest algorithm using which signature is created. Provide null or empty string or 'default' to set default algorithm
      provider - name the provider used to perform signature. Provide null or empty string to set 'preferred'
      Returns:
      string representation of signature block in proper format
      Throws:
      ScriptSignatureException - when one or more parameter are null or empty
    • containSignature

      public static boolean containSignature​(ScriptType scriptType, InputStream inputStream) throws ScriptSignatureException
      Checks the given input stream to see whether it contains signature or not.
      Parameters:
      scriptType - provide ScriptType instance of stream for script
      inputStream - provide InputStream to check for signature
      Returns:
      true if signature is found or false if signature is not found
      Throws:
      ScriptSignatureException - when signature format is improper
    • isSelfSignedCertificate

      public static boolean isSelfSignedCertificate​(Certificate certificate) throws ScriptSignatureException
      Checks 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 or false if certificate is CA signed
      Throws:
      ScriptSignatureException - when certificate is not provided or there is an error while retrieving certificate