public class PKCS7
extends java.lang.Object
SignedData ContentInfo
type, where to the type of data signed is plain Data.
For signedData, crls, attributes and
PKCS#6 Extended Certificates are not supported.| Constructor and Description |
|---|
PKCS7(com.tencent.kona.sun.security.x509.AlgorithmId[] digestAlgorithmIds,
ContentInfo contentInfo,
java.security.cert.X509Certificate[] certificates,
SignerInfo[] signerInfos) |
PKCS7(com.tencent.kona.sun.security.x509.AlgorithmId[] digestAlgorithmIds,
ContentInfo contentInfo,
java.security.cert.X509Certificate[] certificates,
java.security.cert.X509CRL[] crls,
SignerInfo[] signerInfos)
Construct an initialized PKCS7 block.
|
PKCS7(byte[] bytes)
Unmarshals a PKCS7 block from its encoded form, parsing the
encoded bytes.
|
PKCS7(com.tencent.kona.sun.security.util.DerInputStream derin)
Unmarshals a PKCS7 block from its encoded form, parsing the
encoded bytes from the DerInputStream.
|
PKCS7(java.io.InputStream in)
Unmarshals a PKCS7 block from its encoded form, parsing the
encoded bytes from the InputStream.
|
| Modifier and Type | Method and Description |
|---|---|
void |
encodeSignedData(com.tencent.kona.sun.security.util.DerOutputStream out)
Encodes the signed data to a DerOutputStream.
|
static byte[] |
generateNewSignedData(java.lang.String sigalg,
java.security.Provider sigProvider,
java.security.PrivateKey privateKey,
java.security.cert.X509Certificate[] signerChain,
byte[] content,
boolean internalsf,
boolean directsign,
java.util.function.Function<byte[],PKCS9Attributes> ts)
Generate a PKCS7 data block.
|
static byte[] |
generateSignedData(byte[] signature,
java.security.cert.X509Certificate[] signerChain,
byte[] content,
java.lang.String signatureAlgorithm,
java.net.URI tsaURI,
java.lang.String tSAPolicyID,
java.lang.String tSADigestAlg)
Assembles a PKCS #7 signed data message that optionally includes a
signature timestamp.
|
static byte[] |
generateTimestampToken(Timestamper tsa,
java.lang.String tSAPolicyID,
java.lang.String tSADigestAlg,
byte[] toBeTimestamped)
Requests, processes and validates a timestamp token from a TSA using
common defaults.
|
java.security.cert.X509Certificate |
getCertificate(java.math.BigInteger serial,
X500Name issuerName)
Returns the X.509 certificate listed in this PKCS7 block
which has a matching serial number and Issuer name, or
null if one is not found.
|
java.security.cert.X509Certificate[] |
getCertificates()
Returns the X.509 certificates listed in this PKCS7 block.
|
ContentInfo |
getContentInfo()
Returns the content information specified in this PKCS7 block.
|
java.security.cert.X509CRL[] |
getCRLs()
Returns the X.509 crls listed in this PKCS7 block.
|
com.tencent.kona.sun.security.x509.AlgorithmId[] |
getDigestAlgorithmIds()
Returns the message digest algorithms specified in this PKCS7 block.
|
SignerInfo[] |
getSignerInfos()
Returns the signer's information specified in this PKCS7 block.
|
static java.net.URI |
getTimestampingURI(java.security.cert.X509Certificate tsaCertificate)
Examine the certificate for a Subject Information Access extension
(RFC 5280).
|
java.math.BigInteger |
getVersion()
Returns the version number of this PKCS7 block.
|
boolean |
isOldStyle()
Returns true if this is a JDK1.1.x-style PKCS#7 block, and false
otherwise.
|
java.lang.String |
toString()
Returns the PKCS7 block in a printable string form.
|
SignerInfo[] |
verify()
Returns all signerInfos which self-verify.
|
SignerInfo[] |
verify(byte[] bytes)
Returns all signerInfos which self-verify.
|
SignerInfo |
verify(SignerInfo info,
byte[] bytes)
This verifies a given SignerInfo.
|
public PKCS7(java.io.InputStream in)
throws java.io.IOException
in - an input stream holding at least one PKCS7 block.ParsingException - on parsing errors.java.io.IOException - on other errors.public PKCS7(com.tencent.kona.sun.security.util.DerInputStream derin)
throws ParsingException
derin - a DerInputStream holding at least one PKCS7 block.ParsingException - on parsing errors.public PKCS7(byte[] bytes)
throws ParsingException
bytes - the encoded bytes.ParsingException - on parsing errors.public PKCS7(com.tencent.kona.sun.security.x509.AlgorithmId[] digestAlgorithmIds,
ContentInfo contentInfo,
java.security.cert.X509Certificate[] certificates,
java.security.cert.X509CRL[] crls,
SignerInfo[] signerInfos)
digestAlgorithmIds - the message digest algorithm identifiers.contentInfo - the content information.certificates - an array of X.509 certificates.crls - an array of CRLssignerInfos - an array of signer information.public PKCS7(com.tencent.kona.sun.security.x509.AlgorithmId[] digestAlgorithmIds,
ContentInfo contentInfo,
java.security.cert.X509Certificate[] certificates,
SignerInfo[] signerInfos)
public void encodeSignedData(com.tencent.kona.sun.security.util.DerOutputStream out)
throws java.io.IOException
out - the DerOutputStream to write the encoded data to.java.io.IOException - on encoding errors.public SignerInfo verify(SignerInfo info, byte[] bytes) throws java.security.NoSuchAlgorithmException, java.security.SignatureException
info - the signer information.bytes - the DER encoded content information.java.security.NoSuchAlgorithmException - on unrecognized algorithms.java.security.SignatureException - on signature handling errors.public SignerInfo[] verify(byte[] bytes) throws java.security.NoSuchAlgorithmException, java.security.SignatureException
bytes - the DER encoded content information.java.security.NoSuchAlgorithmException - on unrecognized algorithms.java.security.SignatureException - on signature handling errors.public SignerInfo[] verify() throws java.security.NoSuchAlgorithmException, java.security.SignatureException
java.security.NoSuchAlgorithmException - on unrecognized algorithms.java.security.SignatureException - on signature handling errors.public java.math.BigInteger getVersion()
public com.tencent.kona.sun.security.x509.AlgorithmId[] getDigestAlgorithmIds()
public ContentInfo getContentInfo()
public java.security.cert.X509Certificate[] getCertificates()
public java.security.cert.X509CRL[] getCRLs()
public SignerInfo[] getSignerInfos()
public java.security.cert.X509Certificate getCertificate(java.math.BigInteger serial,
X500Name issuerName)
serial - the serial number of the certificate to retrieve.issuerName - the Distinguished Name of the Issuer.public java.lang.String toString()
toString in class java.lang.Objectpublic boolean isOldStyle()
public static byte[] generateNewSignedData(java.lang.String sigalg,
java.security.Provider sigProvider,
java.security.PrivateKey privateKey,
java.security.cert.X509Certificate[] signerChain,
byte[] content,
boolean internalsf,
boolean directsign,
java.util.function.Function<byte[],PKCS9Attributes> ts)
throws java.security.SignatureException,
java.security.InvalidKeyException,
java.io.IOException,
java.security.NoSuchAlgorithmException
sigalg - signature algorithm to be usedsigProvider - (optional) providerprivateKey - signer's private kysignerChain - signer's certificate chaincontent - the content to signinternalsf - whether the content should be included in outputdirectsign - if the content is signed directly or through authattrsts - (optional) timestamperjava.security.SignatureException - if signing failedjava.security.InvalidKeyException - if key cannot be usedjava.io.IOException - should not happen here, all byte arrayjava.security.NoSuchAlgorithmException - if siglag is badpublic static byte[] generateSignedData(byte[] signature,
java.security.cert.X509Certificate[] signerChain,
byte[] content,
java.lang.String signatureAlgorithm,
java.net.URI tsaURI,
java.lang.String tSAPolicyID,
java.lang.String tSADigestAlg)
throws java.security.cert.CertificateException,
java.io.IOException,
java.security.NoSuchAlgorithmException
signature - the signature bytessignerChain - the signer's X.509 certificate chaincontent - the content that is signed; specify null to not include
it in the PKCS7 datasignatureAlgorithm - the name of the signature algorithmtsaURI - the URI of the Timestamping Authority; or null if no
timestamp is requestedtSAPolicyID - the TSAPolicyID of the Timestamping Authority as a
numerical object identifier; or null if we leave the TSA server
to choose one. This argument is only used when tsaURI is providedjava.security.NoSuchAlgorithmException - The exception is thrown if the signature
algorithm is unrecognised.java.security.cert.CertificateException - The exception is thrown if an error occurs
while processing the signer's certificate or the TSA's
certificate.java.io.IOException - The exception is thrown if an error occurs while
generating the signature timestamp or while generating the signed
data message.public static java.net.URI getTimestampingURI(java.security.cert.X509Certificate tsaCertificate)
accessMethod field should contain the object
identifier defined for timestamping: 1.3.6.1.5.5.7.48.3 and its
accessLocation field should contain an HTTP or HTTPS URL.tsaCertificate - (optional) X.509 certificate for the TSA.public static byte[] generateTimestampToken(Timestamper tsa, java.lang.String tSAPolicyID, java.lang.String tSADigestAlg, byte[] toBeTimestamped) throws java.io.IOException, java.security.cert.CertificateException
tsa - the timestamping authority to usetSAPolicyID - the TSAPolicyID of the Timestamping Authority as a
numerical object identifier; or null if we leave the TSA server
to choose onetoBeTimestamped - the token that is to be timestampedjava.io.IOException - The exception is thrown if an error occurs while
communicating with the TSA, or a non-null
TSAPolicyID is specified in the request but it
does not match the one in the replyjava.security.cert.CertificateException - The exception is thrown if the TSA's
certificate is not permitted for timestamping.