org.eclipse.ease.sign

## Class PerformSignature

- java.lang.Object
- - org.eclipse.ease.sign.PerformSignature

    public class PerformSignature
    extends java.lang.Object

Class containing methods to perform signature. Methods include loading of keystore, private key and performing signature to provided file.

### Constructor Summary

Constructors
Constructor and Description
`PerformSignature()`

### Method Summary

All Methods Static Methods Concrete Methods
`static java.lang.String` `createSignature(java.security.KeyStore keyStore, java.io.InputStream dataStream, java.lang.String alias, java.lang.String privateKeyPass, java.lang.String provider, java.lang.String messageDigestAlgo)` Initializes private key and gets signature of provided file.
`static java.util.Collection<java.lang.String>` `getAliases(java.security.KeyStore keyStore)` Gets all aliases from keystore.
`static java.lang.String` `getCertificate(java.security.KeyStore keyStore, java.lang.String alias, boolean canAttachSelfSign)` Obtains certificate for corresponding alias.
`static java.security.KeyStore` `loadKeyStore(java.io.InputStream inputStream, java.lang.String type, java.lang.String provider, java.lang.String keyStorePass)` Checks keystore of given type and provider can be instantiated and if so, instantiates keystore.

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### PerformSignature

    public PerformSignature()

### Method Detail

#### loadKeyStore

    public static java.security.KeyStore loadKeyStore(java.io.InputStream inputStream,
                                                      java.lang.String type,
                                                      java.lang.String provider,
                                                      java.lang.String keyStorePass)
                                               throws ScriptSignatureException,
                                                      java.security.UnrecoverableKeyException,
                                                      java.io.IOException

Checks keystore of given type and provider can be instantiated and if so, instantiates keystore. Then, loads the keyStore from file using provided password.

Parameters:
  `inputStream` - provide inputStream of keystore
  `type` - name type of the keystore like JKS, JCEKS, PKCS12, PKCS12S2. Provide `null` or empty string or 'default' to set default type
  `provider` - name provider of the keystore like SUN, SUNRsaSign, SUNJCE, etc. Provide `null` or empty string or 'preferred' to let system take decision
  `keyStorePass` - provide password to unlock keystore
Returns:
  instance of keystore if loaded properly
Throws:
  `ScriptSignatureException` - when exception can be recovered without closing the application. For e.g., arguments provided for keystore or password are invalid, keystore file can't be read, etc.
  `java.security.UnrecoverableKeyException` - when password for keystore is incorrect
  `java.io.IOException` - when there is an error loading keystore because of IO of format problem

#### getAliases

    public static java.util.Collection<java.lang.String> getAliases(java.security.KeyStore keyStore)

Gets all aliases from keystore.

Parameters:
  `keyStore` - provide keystore instance to read aliases
Returns:
  collection of string of aliases in keystore or `null` if keystore is not loaded properly

#### getCertificate

    public static java.lang.String getCertificate(java.security.KeyStore keyStore,
                                                  java.lang.String alias,
                                                  boolean canAttachSelfSign)
                                           throws ScriptSignatureException

Obtains certificate for corresponding alias.

Parameters:
  `keyStore` - provide instance of loaded keystore
  `alias` - provide alias of which certificate is required
  `canAttachSelfSign` - tell whether to allow to attach self-signed certificate
Returns:
  certificate chain in Base64 String format, each certificate separated by colon(:) or `null` if keystore is not initialized properly
Throws:
  `ScriptSignatureException` - if alias can't be found or certificate can't be loaded

#### createSignature

    public static java.lang.String createSignature(java.security.KeyStore keyStore,
                                                   java.io.InputStream dataStream,
                                                   java.lang.String alias,
                                                   java.lang.String privateKeyPass,
                                                   java.lang.String provider,
                                                   java.lang.String messageDigestAlgo)
                                            throws ScriptSignatureException,
                                                   java.security.UnrecoverableKeyException

Initializes private key and gets signature of provided file.

Parameters:
  `keyStore` - provide instance of loaded keystore
  `dataStream` - give input stream of the script which is to be signed
  `alias` - give alias corresponding to private key used to sign file
  `privateKeyPass` - provide password protecting the private key
  `provider` - give provider used to perform signature. Provide `null` or empty string or 'preferred' to let system take decision
  `messageDigestAlgo` - name the message-digest algorithm to perform signature. Provide `null` or empty string or 'default' to chose default algorithm
Returns:
  provider of signature and signature in string Base64 format separated by colon(:) or `null` if keystore not initialized properly
Throws:
  `ScriptSignatureException` - if alias or privateKeyPass is `null`, signature can't be performed, password to alias is wrong, parameters for private key are wrong
  `java.security.UnrecoverableKeyException` - when password for alias is incorrect