|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--java.util.AbstractCollection
|
+--java.util.AbstractList
|
+--java.util.ArrayList
|
+--codec.asn1.ASN1AbstractCollection
|
+--codec.asn1.ASN1Sequence
|
+--codec.pkcs7.SignedAndEnvelopedData
The definition of this structure is:
SignedAndEnvelopedData ::= SEQUENCE {
version Version,
recipientInfos RecipientInfos,
digestAlgorithms DigestAlgorithmIdentifiers,
encryptedContentInfo EncryptedContentInfo,
certificates
[0] IMPLICIT ExtendedCertificatesAndCertificates OPTIONAL,
crls
[1] IMPLICIT CertificateRevocationLists OPTIONAL,
signerInfos SignerInfos
}
DigestAlgorithmIdentifiers ::= SET OF DigestAlgorithmIdentifier
SignerInfos ::= SET OF SignerInfo
Please note that SignerInfo structures only store the issuer
and serial number of the signing certificate but not the certificate itself.
Neither are certificates added automatically by this class when signing is
done. If a certificate shall be included with an instance of this class then
it must be added explicitly by calling addCertificate(..).
The encryption and decryption methods of this class do not work like
update(...) of a Cipher class but encrypt and
decrypt data with a freshly initialized cipher instance.
| Field Summary | |
protected ASN1Set |
cache_
The cache encoded X.509 certificates. |
protected Certificates |
certs_
The X.509 certificates. |
protected ASN1Set |
crls_
The revocation lists. |
protected ASN1Set |
digestID_
The DigestAlgorithmIdentifiers. |
protected CertificateFactory |
factory_
The certificate factory that is used for decoding certificates. |
protected EncryptedContentInfo |
info_
The EncryptedContentInfo. |
protected ASN1SetOf |
recipients_
The RecipientInfos. |
protected ASN1SetOf |
sInfos_
The SignerInfos. |
| Fields inherited from class java.util.AbstractList |
modCount |
| Fields inherited from interface codec.util.CertificateSource |
ALL, DATA_ENCIPHERMENT, KEY_AGREEMENT, KEY_CERT_SIGN, KEY_ENCIPHERMENT, NON_REPUDIATION |
| Constructor Summary | |
SignedAndEnvelopedData()
Creates an instance ready for decoding. |
|
SignedAndEnvelopedData(SecretKey bek,
String bea,
AlgorithmParameters params)
Creates an instance that is initialized with the given secret key and algorithm parameters. |
|
| Method Summary | |
void |
addCertificate(X509Certificate cert)
Adds the given certificate to this structure if none with the same issuer and serial number already exists. |
void |
addRecipient(X509Certificate cert)
This method adds a recipient to the list of recipients. |
void |
addSignerInfo(SignerInfo info)
Adds the given SignerInfo to this instance. |
Iterator |
certificates(Principal subject)
Retrieves certificates based on the distinguished name of the certificate's subject. |
Iterator |
certificates(Principal subject,
int keyUsage)
Retrieves certificates based on the distinguished name of the certificate's subject and a number of key usage bits. |
byte[] |
decryptBulkData(byte[] b)
|
void |
decryptBulkData(InputStream in,
OutputStream out)
This method reads encrypted bulk data from the input stream, decrypts and writes the decrypted data to the given output stream. |
byte[] |
encryptBulkData(byte[] b)
|
void |
encryptBulkData(InputStream in,
OutputStream out)
This method reads plaintext bulk data from the input stream, encrypts it and writes the encrypted data to the given output stream. |
X509Certificate |
getCertificate(Principal issuer,
BigInteger serial)
This method retrieves a certificate based on the distinguished name of the certificate's issuer as well as its serial number, as assigned by the issuer. |
List |
getCertificates()
This method returns the certificates stored in this structure. |
ASN1Type |
getContent()
This method retrieves the content of this structure, consisting of the ASN.1 type embedded in the ContentInfo structure. |
ASN1ObjectIdentifier |
getContentType()
Returns the content type of the content embedded in this structure. |
byte[] |
getData()
This method decrypts and returns the decrypted data contained in this instance or null if there is no contained data. |
ASN1ObjectIdentifier |
getOID()
Returns the OID of this structure. |
RecipientInfo |
getRecipientInfo(X509Certificate cert)
This method retrieves the RecipientInfo macthing
the given certificate or null if there is no such
recipient. |
List |
getRecipientInfos()
This method returns an unmodifiable list view on the RecipientInfos of this structure. |
SecretKey |
getSecretKey()
This method returns the secret bulk encryption key if the underlying EncryptedContentInfo structure is already initialized properly (by calling one of this object's init methods). |
SignerInfo |
getSignerInfo(X509Certificate cert)
Returns the SignerInfo that matches the given certificate. |
List |
getSignerInfos()
This method returns the SignerInfos of the signers of
this structure. |
boolean |
hasRecipient(X509Certificate cert)
This method checks if the given certificate is listed as a recipient by comparing the issuer and serial number of the given certificate with those listed in the recipient infos of this
instance. |
void |
init(X509Certificate cert,
PrivateKey kdk)
Initializes this instance for encryption/decryption. |
boolean |
isReady()
This method returns true if this instance is ready for
encryption/decryption without further initialization. |
void |
setCertificateFactory(CertificateFactory factory)
Sets the certificate factory to use for decoding certificates. |
void |
setContentType(ASN1ObjectIdentifier oid)
Sets the content type to the given OID. |
void |
setData(byte[] b)
This method wraps the given bytes into a Data type and sets
it as the content.
|
void |
setData(InputStream in)
Encrypts the given data and inserts it as Data content. |
void |
setDataContentType()
Sets the content type to Data and clears the actual content.
|
String |
toString()
Returns a string representation of this object. |
| Methods inherited from class codec.asn1.ASN1Sequence |
getTag |
| Methods inherited from class codec.asn1.ASN1AbstractCollection |
checkConstraints, decode, encode, getCollection, getConstraint, getTagClass, getValue, isExplicit, isOptional, isType, readExternal, setConstraint, setExplicit, setOptional, writeExternal |
| Methods inherited from class java.util.ArrayList |
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, removeRange, set, size, toArray, toArray, trimToSize |
| Methods inherited from class java.util.AbstractList |
equals, hashCode, iterator, listIterator, listIterator, subList |
| Methods inherited from class java.util.AbstractCollection |
containsAll, remove, removeAll, retainAll |
| Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface codec.asn1.ASN1Type |
checkConstraints, decode, encode, getConstraint, getTag, getTagClass, getValue, isExplicit, isOptional, isType, setConstraint, setExplicit, setOptional |
| Methods inherited from interface java.util.Collection |
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray |
| Methods inherited from interface java.util.List |
containsAll, equals, hashCode, iterator, listIterator, listIterator, remove, removeAll, retainAll, subList |
| Field Detail |
protected ASN1Set digestID_
protected Certificates certs_
protected ASN1SetOf sInfos_
SignerInfos.protected ASN1Set crls_
protected ASN1SetOf recipients_
protected EncryptedContentInfo info_
EncryptedContentInfo.protected ASN1Set cache_
protected CertificateFactory factory_
| Constructor Detail |
public SignedAndEnvelopedData()
public SignedAndEnvelopedData(SecretKey bek,
String bea,
AlgorithmParameters params)
throws InvalidAlgorithmParameterException
init method for adding
recipients.bek - The secret key to use for bulk encryption.bea - The name of the bulk encryption algorithm.params - The AlgorithmParameters of the bulk encryption algorithm.InvalidAlgorithmParameterException - just what is says...| Method Detail |
public void addCertificate(X509Certificate cert)
cert - The certificate to add.
public void addRecipient(X509Certificate cert)
throws GeneralSecurityException,
BadNameException
EncryptedContentInfo is initialized
properly. This is done by either of two means:
init with a certificate that is listed as
recipient and appropriate private key.
RecipientInfo instance is created and added to the
list of recipient infos in this instance.cert - The certificate of the recipient.GeneralSecurityException - if some cipher operation fails. The reason can
bedetermined from the actual subclass that is thrown.BadNameException - if the issuer name in the certificate cannot be parsed.public void addSignerInfo(SignerInfo info)
SignerInfo to this instance. This
method should be used rarely. In general, the signing methods take care
of adding SignerInfo
instances. Explicit adding of a
SignerInfo
is provided only in those cases where fine
control of the creation of signatures is required.addSignerInfo in interface Signableinfo - The SignerInfo to add.NullPointerException - if the info is null.public Iterator certificates(Principal subject)
CertificateSourcecertificates in interface CertificateSourcecodec.util.CertificateSourcesubject - The subject DN of the certificate that should be
retrieved.Iterator of all known certificates with the
given subject DN.CertificateIterator
public Iterator certificates(Principal subject,
int keyUsage)
CertificateSourcecertificates in interface CertificateSourcecodec.util.CertificateSourcesubject - The subject DN of the certificate that should be
retrieved. A value of null matches every
subject DN.keyUsage - The mask of key usage bits; at least one of these bits
must be set in the key usage extension of matching
certificates. A value of 0 disables key usage checking.Iterator of all known certificates with the
given subject DN that match at least one of the given key usage
bits.CertificateIterator
public void decryptBulkData(InputStream in,
OutputStream out)
throws IOException,
GeneralSecurityException
in - The input stream from which the data is read.out - The output stream to which the data is written.
public byte[] decryptBulkData(byte[] b)
throws GeneralSecurityException
public void encryptBulkData(InputStream in,
OutputStream out)
throws IOException,
GeneralSecurityException
in - The input stream from which the data is read.out - The output stream to which the data is written.
public byte[] encryptBulkData(byte[] b)
throws GeneralSecurityException
public X509Certificate getCertificate(Principal issuer,
BigInteger serial)
CertificateSourcegetCertificate in interface CertificateSourcecodec.util.CertificateSourceissuer - The issuer distinguished name.serial - The serial number.null if it is not found.public List getCertificates()
X509Certificate.
public ASN1Type getContent()
throws GeneralSecurityException
Data. If it is not data then the authenticated content type
must be given as an authenticated attribute in all the SignerInfo structures.getContent in interface Signablepublic ASN1ObjectIdentifier getContentType()
getContentType in interface Signable
public byte[] getData()
throws GeneralSecurityException,
NoSuchElementException
null if there is no contained data.IllegalStateException - if the DEK is not initialized.NoSuchElementException - if the content type is not Data.GeneralSecurityException - if a cipher operation fails.public ASN1ObjectIdentifier getOID()
getOID in interface ASN1RegisteredTypepublic RecipientInfo getRecipientInfo(X509Certificate cert)
RecipientInfo macthing
the given certificate or null if there is no such
recipient.cert - The certificate that identifies the recipient.null
if no
matching recipient was found.public List getRecipientInfos()
RecipientInfos of this structure.public SecretKey getSecretKey()
init methods). If the key is
not available (yet) then null is returned.null.IllegalStateException - if this instance is not yet initialized.public SignerInfo getSignerInfo(X509Certificate cert)
SignerInfo that matches the given certificate.getSignerInfo in interface Signablecert - The certificate matching the SignerInfo
to
be retrieved.SignerInfo or null if no
matching one is found.public List getSignerInfos()
SignerInfos of the signers of
this structure.public boolean hasRecipient(X509Certificate cert)
recipient infos of this
instance.cert - The certificate that identifies the recipient.true if a recipient who matches the given
certificate is included in this structure.
public void init(X509Certificate cert,
PrivateKey kdk)
throws GeneralSecurityException,
NoSuchElementException
RecipientInfo matching the given certificate and
calls init
of the EncryptedContentInfo contained in
this structure.
This method need to be called only if this instance was not initialized with a secret key for bulk encryption, but was initialized through parsing it from a DER stream. In other words, this method is probably used only when reading EnvelopedData sent by someone else but hardly ever if it is generated.
Please note that, once this instance is properly initialized, additional
recipients might be added to it unless this structure is protected by
integrity measures (such as wrapping it in a
SignedData structure.
kdk - The private Key Decryption Key required to decrypt
the DEK.cert - The certificate matching the private key.GeneralSecurityException - if some cipher operation fails.NoSuchElementException - if no matching RecipientInfo is
found in this instance.public boolean isReady()
true if this instance is ready for
encryption/decryption without further initialization.true if it is ready.public void setCertificateFactory(CertificateFactory factory)
factory - The certificate factory or null
if the
default X.509 factory shall be used.public void setContentType(ASN1ObjectIdentifier oid)
null. This method should be called if the content to be
signed is external (not inserted into this structure).
If this structure is signed with the Signer then the
SignerInfo that is passed to it must have either:
oid.
oid as its value will be added to the
SignerInfo automatically (if the content type is not
Data or at least one other authenticated attribute is
already in that SignerInfo.oid - The OID that identifies the content type of the signed
data.NullPointerException - if oid is null.
public void setData(byte[] b)
throws IOException,
GeneralSecurityException
Data type and sets
it as the content.
Please note that the signing process implemented in this class does not
care about the content. Setting a content before signing does not
sign the content. The data to be signed must always be passed to one of
the
update methods.
b - The opaque contents to embed in this structure.IllegalStateException - if the DEK is not initialized.GeneralSecurityException - if something nasty happens while encrypting such as
algorithms not found, bad paddings et cetera.
public void setData(InputStream in)
throws GeneralSecurityException,
IOException
Data content. The
stream is not closed.IllegalStateException - if the DEK is not initialized.GeneralSecurityException - if something nasty happens while encrypting such as
algorithms not found, bad paddings et cetera.public void setDataContentType()
Data and clears the actual content.
Call this method when external data is signed, and no particular content
type shall be used. This method calls
setContentType(new ASN1ObjectIdentifier(DATA_OID))
.public String toString()
toString in class ASN1AbstractCollection
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||