public final class JarSigner extends Object
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 | Description |
---|---|---|
static class |
JarSigner.Builder |
A mutable builder class that can create an immutable JarSigner from various signing-related parameters. |
Modifier and Type | Method | Description |
---|---|---|
String |
getDigestAlgorithm() |
Returns the digest algorithm for this JarSigner . |
String |
getProperty |
Returns the value of an additional implementation-specific property indicated by the specified key. |
String |
getSignatureAlgorithm() |
Returns the signature algorithm for this JarSigner . |
String |
getSignerName() |
Returns the signer name of this JarSigner . |
URI |
getTsa() |
Returns the URI of the Time Stamping Authority (TSA). |
void |
sign |
Signs a file into an OutputStream . |
public void sign(ZipFile file, OutputStream os)
OutputStream
. This method will not close file
or os
. 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.
file
- the file to sign.os
- the output stream.JarSignerException
- if the signing fails.public String getDigestAlgorithm()
JarSigner
. The return value is never null.
public String getSignatureAlgorithm()
JarSigner
. The return value is never null.
public URI getTsa()
public String getSignerName()
JarSigner
. The return value is never null.
public String getProperty(String key)
JarSigner.Builder.setProperty(java.lang.String, java.lang.String)
for a list of properties this implementation supports. All property names are case-insensitive.key
- the name of the property.UnsupportedOperationException
- if the key is not supported by this implementation.
© 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/21/docs/api/jdk.jartool/jdk/security/jarsigner/JarSigner.html