|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--iaik.pkcs.pkcs7.ContentInfo
This class represents the non-stream implemention of the PKCS#7 ContentInfo
type.
The PKCS#7 standard describes a general syntax for data that may have cryptography applied to it, such as digital signatures and digital envelopes.
The ASN.1 type ContentInfo
type associates a content type
(data, signedData, envelopedData, signedAndEnvelopedData, digestedData,
encryptedData
) with some particular content for specifying a
general syntax for content exchanged between entities according the PKCS#7 standard:
ContentInfo ::= SEQUENCE { contentType ContentType, content [0] EXPLICIT ANY DEFINED BY contentType OPTIONAL }
ContentType ::= OBJECT IDENTIFIER
If the optional content
is not present, the content value has to be
supplied by other means.
This class consists of two parts: the first static part implements a factory for registering all the non-stream implementations of the several PKCS#7 content types. And the second non-static part provides constructors and methods for creating, en- and decoding non-stream PKCS#7 content type objects in the usual way.
The stream-supporting equivalent to this class is implemented by the
ContentInfoStream
class.
When creating a new ContentInfo to be sent use the ContentInfo(Content)
constructor
and subsequently call the toASN1Object
or writeTo
method, e.g.:
// create a PKCS#7 object, e.g. Data: Data data = ...; ... // create a ContentInfo for the PKCS#7 object and encode it to a stream: ContentInfo ci = new ContentInfo(data); OutputStream encoded_stream = ...; ci.writeTo(encoded_stream);However, if you want to sent a ContentInfo without any content, you only have to supply the content type identifier when
creating
a ContentInfo object, e.g.:
ContentInfo ci = new ContentInfo(ObjectID.pkcs7_data); ci.writeTo(encoded_stream);After creating an ContentInfo instance for parsing an already existing ContentInfo object supplied as
ASN.1 object
or DER encoded
from an input stream, you may
use the getContentInputStream
method for getting
the unparsed content as input stream, or you may call the
getContent
method for getting the already parsed content as
Content
descendant.
The different usage may be illustrated by means of the two types of a SignedData
message. When receiving a ContentInfo holding an implicit message the
content is included in the SignedData object, and so the getContent
method may be appropriate for getting the already parsed SignedData
content, e.g.:
// create a ContentInfo from the encoding: ContentInfo ci = new ContentInfo(encodedStream); // ask for the content type: if (ci.getContentType().equals(ObjectID.pkcs7_signedData)) { // get the SignedData content: SignedData signedData = (SignedData)ci.getContent() // proceed as usual for reading the data, getting the SignerInfos and // verifying the signatures } else { throw new PKCSParsingException("Error! Expected content type SignedData!"); }However, when receiving a ContentInfo holding an explicit message where the content is not included in the SignedData object, you may want to use the the
SignedData(byte[] content, AlgorithmID[] hashAlgorithms)
constructor for
initializing a SignedData object with raw content and hash
algorithms in the usual way, and subsequently decode the received SignedData object
by feeding the decode
method with the DER encoded SignedData object obtained from the ContentInfo by
calling the getContentInputStream
method, e.g.:
// the raw data received by other means, supplied by a byte array: byte[] message = ...; // the hash algorithms (e.g. parsed from the headers of a S/MIME multipart/signed entity): AlgorithmID[] algIDs = { AlgorithmID.sha1, AlgorithmID.md5 }; // the DER encoded content info, supplied from an input stream: InputStream encoded_stream = ...; // create a SignedData object from raw data and hash algorithms: SignedData signed_data = new SignedData(message, algIDs); // create a ContentInfo from the DER encoding: ContentInfo ci = new ContentInfo(encoded_stream); // check the content type: if (ci.getContentType().equals(ObjectID.pkcs7_signedData)) { // now decode the DER encoded SignedData obtained from the ContentInfo: signed_data.decode(ci.getContentInputStream()); } else { throw new PKCSParsingException("Error! Expected a SignedData content!"); } // proceed as usual for reading the content, getting SignerInfos and verifying signatures ...
Data
,
DigestedData
,
EncryptedData
,
EnvelopedData
,
SignedAndEnvelopedData
,
SignedData
,
Content
Constructor Summary | |
ContentInfo(ASN1Object obj)
Creates a PKCS#7 ContentInfo from an ASN1Object. |
|
ContentInfo(Content content)
Creates a PKCS#7 ContentInfo from the given content value.
|
|
ContentInfo(InputStream is)
Creates a new ContentInfo where the DER encoded data is read from the given InputStream. |
|
ContentInfo(ObjectID contentType)
Creates an empty PKCS#7 ContentInfo from the given content type.
|
Method Summary | |
static Content |
create(ObjectID oid)
Returns an instance of the specified PKCS#7 content type implementation, defined by its ASN.1 ObjectID. |
static Content |
create(ObjectID oid,
ASN1Object obj)
Returns an instance of the specified PKCS#7 content type implementation, defined by its ASN.1 ObjectID. |
protected void |
decode(DerInputStream is)
Reads and decodes the ContentInfo from a DerInputStream. |
void |
destroyCriticalData()
Destroys the critical data of this object. |
Content |
getContent()
Returns the content of this PKCS#7 ContentInfo. |
InputStream |
getContentInputStream()
Returns the unparsed content of this PKCS#7 ContentInfo as DER encoding. |
ObjectID |
getContentType()
Returns the content type of this PKCS#7 ContentInfo. |
boolean |
hasContent()
Returns true if this ContentInfo has a content. |
static void |
register(ObjectID oid,
Class cls)
Registers a new implementation for a Content defined through the given ObjectID. |
void |
setContent(Content content)
Sets the content of this ContentInfo from the given content value. |
ASN1Object |
toASN1Object()
Returns this PKCS#7 ContentInfo as ASN1Object. |
byte[] |
toByteArray()
Returns this PKCS#7 ContentInfo as DER encoded byte array. |
String |
toString()
Returns a string giving some information about this PKCS#7 ContentInfo. |
String |
toString(boolean detailed)
Returns a string giving some - if requested - detailed information about this PKCS#7 ContentInfo. |
void |
writeTo(OutputStream os)
Writes the DER encoding of this object to the given OutputStream. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public ContentInfo(Content content)
ContentInfo
from the given content value.
The content type object identifier internally is derived from the given content object
by using the getContentType
method.
content
- the content object as Content
descendant.public ContentInfo(ObjectID contentType)
ContentInfo
from the given content type.
Since no content is specified, it is set to null
. The content
value may be supplied by other means.
contentType
- the type of the contentpublic ContentInfo(ASN1Object obj) throws PKCSParsingException
ContentInfo
object which may have been created by using the
toASN1Object
method of this class.
obj
- the PKCS#7 ContentInfo as an ASN1ObjectPKCSParsingException
- if the ASN1Object could not be parsedpublic ContentInfo(InputStream is) throws IOException, PKCSParsingException
ContentInfo
object which may have been written to a stream by using
the writeTo
method of this class.
is
- the InputStream holding a DER encoded PKCS#7 ContentInfo objectIOException
- if an I/O error occurs during reading from the InputStreamPKCSParsingException
- if an error occurs while parsing the objectMethod Detail |
public static Content create(ObjectID oid) throws PKCSException
oid
- the ObjectID of the PKCS#7 content typePKCSException
- if an error occurs when creating the PKCS#7 content objectpublic static Content create(ObjectID oid, ASN1Object obj) throws PKCSParsingException
This method only calls the corresponding create
method of the
ExtensionFactory
for obtaining a non-stream supporting implementation of
the desired PKCS#7 content type implementation, specified by its object identifier.
oid
- the ObjectID of the PKCS#7 content typeobj
- an ASN1Object representing the PKCS#7 content object specified by the given oidPKCSParsingException
- if an error occurs while parsing the objectpublic static void register(ObjectID oid, Class cls)
oid
- the object id of the PKCS#7 content to be registeredcls
- the implementing classprotected void decode(DerInputStream is) throws IOException, PKCSParsingException
DerInputStream
,
internally a DerInputStream is created before parsing the data.is
- the InputStream holding a DER encoded PKCS#7 ContentInfo objectIOException
- if an I/O error occurs during reading from the InputStreamPKCSParsingException
- if an error occurs while parsing the objectpublic ASN1Object toASN1Object() throws PKCSException
ContentInfo
from an ASN1Object by calling the
ContentInfo(ASN1Object obj)
constructor.
public byte[] toByteArray() throws PKCSException
ContentInfo
structure is encoded as ASN.1 SEQUENCE
using the indefinite length encoding scheme:
30 80 ... ... 00 00
PKCSException
- if an error occurs while encoding the objectpublic void writeTo(OutputStream os) throws IOException, PKCSException
ContentInfo
structure is encoded as ASN.1 SEQUENCE
using the indefinite length encoding scheme:
30 80 ... ... 00 00
os
- the OutputStream where the encoding shall be written toIOException
- if an I/O error occurs during writing to the OutputStreamPKCSException
- if an error occurs while encoding the objectpublic boolean hasContent()
public Content getContent()
Content
descendant
or null
if there is no contentpublic InputStream getContentInputStream()
null
.
This method may be useful for parsing an explicit SignedData object that has been
wrapped into a ContentInfo. You can use the
SignedData(byte[] content, AlgorithmID[] hashAlgorithms)
in the normal way
for initializing a SignedData object with raw content and hash algorithms, and
subsequently decode the received SignedData object by feeding the decode
method with the
DER encoded SignedData object obtained from the ContentInfo by calling this
getContentInputStream
method, e.g.:
// the raw data received by other means, supplied as byte array: byte[] message = ...; // the hash algorithms (e.g. parsed from the headers of a S/MIME multipart/signed entity): AlgorithmID[] algIDs = { AlgorithmID.sha1, AlgorithmID.md5 }; // the DER encoded content info, supplied from an input stream: InputStream der_stream = ...; // create a SignedData object from raw data and hash algorithms: SignedData signed_data = new SignedData(message, algIDs); // create a ContentInfo from the DER encoding: ContentInfo ci = new ContentInfo(der_stream); // check the content type: if (ci.getContentType().equals(ObjectID.pkcs7_signedData)) { // now decode the DER encoded SignedData obtained from the ContentInfo: signed_data.decode(ci.getContentInputStream()); } else { throw new PKCSParsingException("Error! Expected a SignedData content!"); } // proceed as usual for getting SignerInfos and verifying signatures ...
null
if there is no content or this method is not called
during the parsing (decoding) processpublic ObjectID getContentType()
public void setContent(Content content)
The content type object identifier internally is derived from the given content object
by using the getContentType
method.
content
- the content object as Content
descendant.public void destroyCriticalData()
public String toString()
toString
in class Object
public String toString(boolean detailed)
detailed
- - whether or not to give detailed information
|
This Javadoc may contain text parts from Internet Standard specifications (RFC 2459, 3280, 3039, 2560, 1521, 821, 822, 2253, 1319, 1321, ,2630, 2631, 2268, 3058, 2984, 2104, 2144, 2040, 2311, 2279, see copyright note) and RSA Data Security Public-Key Cryptography Standards (PKCS#1,3,5,7,8,9,10,12, see copyright note). | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |