|
|||||||||
| 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.EnvelopedData
This class represents the PKCS#7 EnvelopedData type, which is defined as follows:
EnvelopedData ::= SEQUENCE {
version Version,
recipientInfos RecipientInfos,
encryptedContentInfo EncryptedContentInfo
}
RecipientInfos ::= SET OF RecipientInfo
See class RecipientInfo for a description of the
RecipientInfo structure.
| Field Summary | |
static int |
BUFFER_SIZE
The size of the buffer allocated for reading and verifying data in case this is a detached signature file. |
protected ContentInfo |
content_
The ContentInfo. |
protected EncryptedContentInfo |
info_
The EncryptedContentInfo. |
protected ASN1SetOf |
recipients_
The RecipientInfos. |
protected ASN1Integer |
version_
The version of this structure. |
| Fields inherited from class java.util.AbstractList |
modCount |
| Constructor Summary | |
EnvelopedData()
This method calls builds the tree of ASN.1 objects used for decoding this structure. |
|
EnvelopedData(SecretKey bek,
String bea,
AlgorithmParameters params)
Creates an instance that is initialized with the given secret key and algorithm parameters. |
|
| Method Summary | |
void |
addRecipient(X509Certificate cert)
This method adds a recipient to the list of recipients. |
void |
addRecipient(X509Certificate cert,
int encType)
same as above but with an explicit encodingType |
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. |
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. |
ASN1ObjectIdentifier |
getContentType()
Retrieves and returns the content type of the content stored in the encryptedContentInfo of this structure. |
byte[] |
getData()
This method decrypts and returns the decrypted data contained in this instance or null if there is no contained data. |
EncryptedContentInfo |
getEncryptedContentInfo()
This method returns the EncryptedContentInfo embedded in
this instance. |
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). |
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 |
setData(InputStream in)
Encrypts the given data and inserts it as Data content. |
| 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, toString, 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 |
public static final int BUFFER_SIZE
protected ASN1Integer version_
protected ASN1SetOf recipients_
protected EncryptedContentInfo info_
EncryptedContentInfo.protected ContentInfo content_
ContentInfo.| Constructor Detail |
public EnvelopedData()
public EnvelopedData(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 ASN1ObjectIdentifier getOID()
getOID in interface ASN1RegisteredTypepublic ASN1ObjectIdentifier getContentType()
encryptedContentInfo of this structure. This value is
meaningful only if this instance was decoded or initialized properly.public EncryptedContentInfo getEncryptedContentInfo()
EncryptedContentInfo embedded in
this instance. This method is hardly ever used. Its primary purpose is to
allow customized decryption of bulk encryption keys e.g., via SmartCards.
This would work as follows: The application
RecipientInfo from this instance
and extracts the encrypted bulk encryption key and the (asymmetric) key
encryption algorithm identifier (with parameters and algorithm
identifier).
EncryptedContentInfo and from that the
bulk encryption algorithm and the bulk encryption algorithm parameters.
EncryptedContentInfo directly with
the freshly decrypted bulk encryption key.
EncryptedContentInfo instance.
EncryptedContentInfopublic List getRecipientInfos()
RecipientInfos 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 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 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 addRecipient(X509Certificate cert,
int encType)
throws GeneralSecurityException,
BadNameException
cert - encType - GeneralSecurityException - BadNameException -
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 setData(InputStream in)
throws GeneralSecurityException,
IOException
Data content.IllegalStateException - if the DEK is not initialized.GeneralSecurityException - if something nasty happens while encrypting such as
algorithms not found, bad paddings et cetera.
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 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 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 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.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||