Class JarSigner
java.lang.Object
jdk.security.jarsigner.JarSigner
An immutable utility class to sign a jar file.
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);
}
- Since:
- 9
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA mutable builder class that can create an immutableJarSignerfrom various signing-related parameters. -
Method Summary
Modifier and TypeMethodDescriptionReturns the digest algorithm for thisJarSigner.getProperty(String key) Returns the value of an additional implementation-specific property indicated by the specified key.Returns the signature algorithm for thisJarSigner.Returns the signer name of thisJarSigner.getTsa()Returns the URI of the Time Stamping Authority (TSA).voidsign(ZipFile file, OutputStream os) Signs a file into anOutputStream.Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()Answers a new instance of the same class as the receiver, whose slots have been filled in with the values in the slots of the receiver.booleanCompares the argument to the receiver, and answers true if they represent the same object using a class specific comparison.protected voidfinalize()Deprecated, for removal: This API element is subject to removal in a future version.May cause performance issues, deadlocks and hangs.getClass()Answers the unique instance of java.lang.Class which represents the class of the receiver.inthashCode()Answers an integer hash code for the receiver.final voidnotify()Causes one thread which iswaiting on the receiver to be made ready to run.final voidCauses all threads which arewaiting on the receiver to be made ready to run.toString()Answers a string containing a concise, human-readable description of the receiver.final voidwait()Causes the thread which sent this message to be made not ready to run pending some change in the receiver (as indicated bynotifyornotifyAll).final voidwait(long time) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.final voidwait(long time, int frac) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.
-
Method Details
-
sign
Signs a file into anOutputStream. This method will not closefileoros.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.
- Parameters:
file- the file to sign.os- the output stream.- Throws:
JarSignerException- if the signing fails.
-
getDigestAlgorithm
Returns the digest algorithm for thisJarSigner.The return value is never null.
- Returns:
- the digest algorithm.
-
getSignatureAlgorithm
Returns the signature algorithm for thisJarSigner.The return value is never null.
- Returns:
- the signature algorithm.
-
getTsa
Returns the URI of the Time Stamping Authority (TSA).- Returns:
- the URI of the TSA.
-
getSignerName
Returns the signer name of thisJarSigner.The return value is never null.
- Returns:
- the signer name.
-
getProperty
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(String, 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.
-