A caller creates a JarSigner.Builder object, (optionally) sets
some parameters, and calls build to create
a JarSigner object. This JarSigner object can then
be used to sign a jar file.
Unless otherwise stated, calling a method of JarSigner or
JarSigner.Builder with a null argument will throw
a NullPointerException.
Example:
JarSigner signer = new JarSigner.Builder(key, certPath) .digestAlgorithm("SHA-256") .signatureAlgorithm("SHA256withRSA") .build(); try (ZipFile in = new ZipFile(inputFile); FileOutputStream out = new FileOutputStream(outputFile)) { signer.sign(in, out); }
| Modifier and Type | Class and Description |
|---|---|
| public static class | JarSigner.
A mutable builder class that can create an immutable |
| pack-priv static class |
| Modifier and Type | Field and Description |
|---|---|
| private final X509Certificate[] | |
| private final String[] | |
| private final Provider | |
| private boolean | |
| private final BiConsumer | |
| private final boolean | |
| pack-priv static final JavaUtilZipFileAccess | |
| private final PrivateKey | |
| private final boolean | |
| private final String | |
| private final String | |
| private final Provider | |
| private final String | |
| private final String | |
| private final URI |
| Modifier and Type | Method and Description |
|---|---|
| public String | |
| private Attributes | |
| private String[] | |
| private ZipEntry | |
| public String | Returns: the value for the property.the name of the property. key)Returns the value of an additional implementation-specific property indicated by the specified key. |
| public String | Returns: the signature algorithm.Returns the signature algorithm for this |
| public String | |
| public URI | |
| public void | sign(ZipFile
the file to sign. file, OutputStream the output stream. os)Signs a file into an |
| private void | |
| private void | |
| private void | |
| private void |
| certChain | back to summary |
|---|---|
| private final X509Certificate[] certChain | |
| digestalg | back to summary |
|---|---|
| private final String[] digestalg | |
| digestProvider | back to summary |
|---|---|
| private final Provider digestProvider | |
| externalFileAttributesDetected | back to summary |
|---|---|
| private boolean externalFileAttributesDetected | |
| handler | back to summary |
|---|---|
| private final BiConsumer<String, String> handler | |
| internalsf | back to summary |
|---|---|
| private final boolean internalsf | |
| JUZFA | back to summary |
|---|---|
| pack-priv static final JavaUtilZipFileAccess JUZFA | |
| privateKey | back to summary |
|---|---|
| private final PrivateKey privateKey | |
| sectionsonly | back to summary |
|---|---|
| private final boolean sectionsonly | |
| sigalg | back to summary |
|---|---|
| private final String sigalg | |
| signerName | back to summary |
|---|---|
| private final String signerName | |
| sigProvider | back to summary |
|---|---|
| private final Provider sigProvider | |
| tSADigestAlg | back to summary |
|---|---|
| private final String tSADigestAlg | |
| tSAPolicyID | back to summary |
|---|---|
| private final String tSAPolicyID | |
| tsaUrl | back to summary |
|---|---|
| private final URI tsaUrl | |
| JarSigner | back to summary |
|---|---|
| private JarSigner(JarSigner. | |
| getDigestAlgorithm | back to summary |
|---|---|
| public String getDigestAlgorithm() Returns the digest algorithm for this The return value is never null.
| |
| getDigestAttributes | back to summary |
|---|---|
| private Attributes getDigestAttributes(ZipEntry ze, ZipFile zf, MessageDigest[] digests) throws IOException | |
| getDigests | back to summary |
|---|---|
| private String[] getDigests(ZipEntry ze, ZipFile zf, MessageDigest[] digests) throws IOException | |
| getManifestFile | back to summary |
|---|---|
| private ZipEntry getManifestFile(ZipFile zf) | |
| getProperty | back to summary |
|---|---|
| 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
| |
| getSignatureAlgorithm | back to summary |
|---|---|
| public String getSignatureAlgorithm() Returns the signature algorithm for this The return value is never null.
| |
| getSignerName | back to summary |
|---|---|
| public String getSignerName() Returns the signer name of this The return value is never null.
| |
| getTsa | back to summary |
|---|---|
| public URI getTsa() Returns the URI of the Time Stamping Authority (TSA).
| |
| sign | back to summary |
|---|---|
| public void sign(ZipFile file, OutputStream os) Signs a file into an If an I/O error or signing error occurs during the signing, then it may do so after some bytes have been written. Consequently, the output stream may be in an inconsistent state. It is strongly recommended that it be promptly closed in this case.
| |
| sign0 | back to summary |
|---|---|
| private void sign0(ZipFile zipFile, OutputStream os) throws IOException, CertificateException, NoSuchAlgorithmException, SignatureException, InvalidKeyException, InvalidParameterSpecException | |
| updateDigests | back to summary |
|---|---|
| private void updateDigests(ZipEntry ze, ZipFile zf, MessageDigest[] digests, Manifest mf) throws IOException | |
| writeBytes | back to summary |
|---|---|
| private void writeBytes(ZipFile zf, ZipEntry ze, ZipOutputStream os) throws IOException | |
| writeEntry | back to summary |
|---|---|
| private void writeEntry(ZipFile zf, ZipOutputStream os, ZipEntry ze) throws IOException | |
JarSigner
from various signing-related parameters.
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final X509Certificate[] | |
| pack-priv String[] | |
| pack-priv Provider | |
| pack-priv BiConsumer | |
| pack-priv boolean | |
| pack-priv final PrivateKey | |
| pack-priv boolean | |
| pack-priv String | |
| pack-priv String | |
| pack-priv Provider | |
| pack-priv String | |
| pack-priv String | |
| pack-priv URI |
| Access | Constructor and Description |
|---|---|
| public | Builder(KeyStore.
the entryKeyStore. of the signer.Creates a |
| public | Builder(PrivateKey
the private key of the signer. privateKey, CertPath the certification path of the signer. certPath)Creates a |
| Modifier and Type | Method and Description |
|---|---|
| public JarSigner | Returns: theJarSigner object.Builds a |
| public JarSigner. | Returns: theJarSigner.Builder itself.the standard name of the algorithm. See
the algorithm)MessageDigest section in the
Java Cryptography Architecture Standard Algorithm Name
Documentation for information about standard algorithm names.Sets the digest algorithm. |
| public JarSigner. | Returns: theJarSigner.Builder itself.the standard name of the algorithm. See
the algorithm, Provider MessageDigest section in the
Java Cryptography Architecture Standard Algorithm Name
Documentation for information about standard algorithm names.the provider. provider)Sets the digest algorithm from the specified provider. |
| public JarSigner. | Returns: theJarSigner.Builder itself.the event handler. handler)Sets en event handler that will be triggered when a |
| public static String | |
| public static String | Returns: the default signature algorithm. Returns null if a default signature algorithm cannot be found. In this case,signatureAlgorithm must be called to specify a
signature algorithm. Otherwise, the build method
will throw an IllegalArgumentException.the private key. key)Gets the default signature algorithm for a private key. |
| private static boolean | |
| public JarSigner. | Returns: theJarSigner.Builder itself.the name of the property. key, String the value of the property. value)Sets an additional implementation-specific property indicated by the specified key. |
| public JarSigner. | Returns: theJarSigner.Builder itself.the standard name of the algorithm. See
the algorithm)Signature section in the
Java Cryptography Architecture Standard Algorithm Name
Documentation for information about standard algorithm names.Sets the signature algorithm. |
| public JarSigner. | Returns: theJarSigner.Builder itself.the standard name of the algorithm. See
the algorithm, Provider Signature section in the
Java Cryptography Architecture Standard Algorithm Name
Documentation for information about standard algorithm names.the provider. provider)Sets the signature algorithm from the specified provider. |
| public JarSigner. | |
| public JarSigner. |
| certChain | back to summary |
|---|---|
| pack-priv final X509Certificate[] certChain | |
| digestalg | back to summary |
|---|---|
| pack-priv String[] digestalg | |
| digestProvider | back to summary |
|---|---|
| pack-priv Provider digestProvider | |
| handler | back to summary |
|---|---|
| pack-priv BiConsumer<String, String> handler | |
| internalsf | back to summary |
|---|---|
| pack-priv boolean internalsf | |
| privateKey | back to summary |
|---|---|
| pack-priv final PrivateKey privateKey | |
| sectionsonly | back to summary |
|---|---|
| pack-priv boolean sectionsonly | |
| sigalg | back to summary |
|---|---|
| pack-priv String sigalg | |
| signerName | back to summary |
|---|---|
| pack-priv String signerName | |
| sigProvider | back to summary |
|---|---|
| pack-priv Provider sigProvider | |
| tSADigestAlg | back to summary |
|---|---|
| pack-priv String tSADigestAlg | |
| tSAPolicyID | back to summary |
|---|---|
| pack-priv String tSAPolicyID | |
| tsaUrl | back to summary |
|---|---|
| pack-priv URI tsaUrl | |
| Builder | back to summary |
|---|---|
| public Builder(KeyStore. Creates a
| |
| Builder | back to summary |
|---|---|
| public Builder(PrivateKey privateKey, CertPath certPath) Creates a
| |
| build | back to summary |
|---|---|
| public JarSigner build() Builds a
This method does not modify internal state of this
| |
| digestAlgorithm | back to summary |
|---|---|
| public JarSigner. Sets the digest algorithm. If no digest algorithm is specified,
the default algorithm returned by
| |
| digestAlgorithm | back to summary |
|---|---|
| public JarSigner. Sets the digest algorithm from the specified provider.
If no digest algorithm is specified, the default algorithm
returned by
| |
| eventHandler | back to summary |
|---|---|
| public JarSigner. Sets en event handler that will be triggered when a
The handler can be used to display signing progress. The first
argument of the handler can be "adding", "signing", or "updating",
and the second argument is the name of the
| |
| getDefaultDigestAlgorithm | back to summary |
|---|---|
| public static String getDefaultDigestAlgorithm() Gets the default digest algorithm. Implementation Note This implementation returns "SHA-384". The value may change in the future.
| |
| getDefaultSignatureAlgorithm | back to summary |
|---|---|
| public static String getDefaultSignatureAlgorithm(PrivateKey key) Gets the default signature algorithm for a private key. For example, SHA384withRSA for a 2048-bit RSA key, and SHA384withECDSA for a 384-bit EC key. Implementation Note This implementation makes use of comparable strengths as defined in Tables 2 and 3 of NIST SP 800-57 Part 1-Rev.5 as well as NIST recommendations as appropriate. Specifically, if an RSA key with a key size greater than 7680 bits, or an EC key with a key size greater than or equal to 512 bits, SHA-512 will be used as the hash function for the signature. Otherwise, SHA-384 will be used unless the key size is too small for resulting signature algorithm. As for DSA keys, the SHA256withDSA signature algorithm is returned regardless of key size. The value may change in the future.
| |
| parseBoolean | back to summary |
|---|---|
| private static boolean parseBoolean(String name, String value) | |
| setProperty | back to summary |
|---|---|
| public JarSigner. Sets an additional implementation-specific property indicated by the specified key. Implementation Note This implementation supports the following properties:
| |
| signatureAlgorithm | back to summary |
|---|---|
| public JarSigner. Sets the signature algorithm. If no signature algorithm
is specified, the default signature algorithm returned by
| |
| signatureAlgorithm | back to summary |
|---|---|
| public JarSigner. Sets the signature algorithm from the specified provider. If no
signature algorithm is specified, the default signature algorithm
returned by
| |
| signerName | back to summary |
|---|---|
| public JarSigner. Sets the signer name. The name will be used as the base name for the signature files. All lowercase characters will be converted to uppercase for signature file names. If a signer name is not specified, the string "SIGNER" will be used.
| |
| tsa | back to summary |
|---|---|
| public JarSigner. Sets the URI of the Time Stamping Authority (TSA). | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv String | baseName
.SF base name |
| pack-priv Manifest | sf
SignatureFile |
| Access | Constructor and Description |
|---|---|
| public | SignatureFile(MessageDigest[] digests, Manifest mf, ManifestDigester md, String baseName, boolean sectionsonly)
|
| Modifier and Type | Method and Description |
|---|---|
| private static String | |
| public String | |
| public String | |
| public void |
| baseName | back to summary |
|---|---|
| pack-priv String baseName .SF base name | |
| sf | back to summary |
|---|---|
| pack-priv Manifest sf SignatureFile | |
| SignatureFile | back to summary |
|---|---|
| public SignatureFile(MessageDigest[] digests, Manifest mf, ManifestDigester md, String baseName, boolean sectionsonly) | |
| getBaseSignatureFilesName | back to summary |
|---|---|
| private static String getBaseSignatureFilesName(String baseName) | |
| getBlockName | back to summary |
|---|---|
| public String getBlockName(PrivateKey privateKey) | |
| getMetaName | back to summary |
|---|---|
| public String getMetaName() | |
| write | back to summary |
|---|---|
| public void write(OutputStream out) throws IOException | |