public class PerformSignature extends Object
Constructor and Description |
---|
PerformSignature() |
Modifier and Type | Method and Description |
---|---|
static String |
createSignature(KeyStore keyStore,
InputStream dataStream,
String alias,
String privateKeyPass,
String provider,
String messageDigestAlgo)
Initializes private key and gets signature of provided file.
|
static Collection<String> |
getAliases(KeyStore keyStore)
Gets all aliases from keystore.
|
static String |
getCertificate(KeyStore keyStore,
String alias,
boolean canAttachSelfSign)
Obtains certificate for corresponding alias.
|
static KeyStore |
loadKeyStore(InputStream inputStream,
String type,
String provider,
String keyStorePass)
Checks keystore of given type and provider can be instantiated and if so, instantiates keystore.
|
public static KeyStore loadKeyStore(InputStream inputStream, String type, String provider, String keyStorePass) throws ScriptSignatureException, UnrecoverableKeyException, IOException
inputStream
- provide inputStream of keystoretype
- name type of the keystore like JKS, JCEKS, PKCS12, PKCS12S2. Provide null
or empty string or 'default' to set default typeprovider
- name provider of the keystore like SUN, SUNRsaSign, SUNJCE, etc. Provide null
or empty string or 'preferred' to let system take
decisionkeyStorePass
- provide password to unlock keystoreScriptSignatureException
- 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.UnrecoverableKeyException
- when password for keystore is incorrectIOException
- when there is an error loading keystore because of IO of format problempublic static Collection<String> getAliases(KeyStore keyStore)
keyStore
- provide keystore instance to read aliasesnull
if keystore is not loaded properlypublic static String getCertificate(KeyStore keyStore, String alias, boolean canAttachSelfSign) throws ScriptSignatureException
keyStore
- provide instance of loaded keystorealias
- provide alias of which certificate is requiredcanAttachSelfSign
- tell whether to allow to attach self-signed certificatenull
if keystore is not initialized properlyScriptSignatureException
- if alias can't be found or certificate can't be loadedpublic static String createSignature(KeyStore keyStore, InputStream dataStream, String alias, String privateKeyPass, String provider, String messageDigestAlgo) throws ScriptSignatureException, UnrecoverableKeyException
keyStore
- provide instance of loaded keystoredataStream
- give input stream of the script which is to be signedalias
- give alias corresponding to private key used to sign fileprivateKeyPass
- provide password protecting the private keyprovider
- give provider used to perform signature. Provide null
or empty string or 'preferred' to let system take decisionmessageDigestAlgo
- name the message-digest algorithm to perform signature. Provide null
or empty string or 'default' to chose default algorithmnull
if keystore not initialized properlyScriptSignatureException
- if alias or privateKeyPass is null
, signature can't be performed, password to alias is wrong, parameters for private key are
wrongUnrecoverableKeyException
- when password for alias is incorrect