- java.lang.Object
-
- jdk.security.jarsigner.JarSigner
-
public final class JarSigner extends Object
An immutable utility class to sign a jar file.A caller creates a
JarSigner.Builderobject, (optionally) sets some parameters, and callsbuildto create aJarSignerobject. ThisJarSignerobject can then be used to sign a jar file.Unless otherwise stated, calling a method of
JarSignerorJarSigner.Builderwith a null argument will throw aNullPointerException.Example:
JarSigner signer = new JarSigner.Builder(key, certPath) .digestAlgorithm("SHA-1") .signatureAlgorithm("SHA1withDSA") .build(); try (ZipFile in = new ZipFile(inputFile); FileOutputStream out = new FileOutputStream(outputFile)) { signer.sign(in, out); }- Since:
- 9
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classJarSigner.BuilderA mutable builder class that can create an immutableJarSignerfrom various signing-related parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetDigestAlgorithm()Returns the digest algorithm for thisJarSigner.StringgetProperty(String key)Returns the value of an additional implementation-specific property indicated by the specified key.StringgetSignatureAlgorithm()Returns the signature algorithm for thisJarSigner.StringgetSignerName()Returns the signer name of thisJarSigner.URIgetTsa()Returns the URI of the Time Stamping Authority (TSA).voidsign(ZipFile file, OutputStream os)Signs a file into anOutputStream.
-
-
-
Method Detail
-
sign
public void sign(ZipFile file, OutputStream os)
- Parameters:
file- the file to sign.os- the output stream.- Throws:
JarSignerException- if the signing fails.
-
getDigestAlgorithm
public String getDigestAlgorithm()
Returns the digest algorithm for thisJarSigner.The return value is never null.
- Returns:
- the digest algorithm.
-
getSignatureAlgorithm
public String getSignatureAlgorithm()
Returns the signature algorithm for thisJarSigner.The return value is never null.
- Returns:
- the signature algorithm.
-
getTsa
public URI getTsa()
Returns the URI of the Time Stamping Authority (TSA).- Returns:
- the URI of the TSA.
-
getSignerName
public String getSignerName()
Returns the signer name of thisJarSigner.The return value is never null.
- Returns:
- the signer name.
-
getProperty
public String getProperty(String key)
Returns the value of an additional implementation-specific property indicated by the specified key. If a property is not set but has a default value, the default value will be returned.- Implementation Note:
- See
JarSigner.Builder.setProperty(java.lang.String, java.lang.String)for a list of properties this implementation supports. All property names are case-insensitive. - Parameters:
key- the name of the property.- Returns:
- the value for the property.
- Throws:
UnsupportedOperationException- if the key is not supported by this implementation.
-
-