public class Data extends DataStream implements Content
Data
.
Each PKCS#7 content type is associated with a specific object identifier, derived from:
pkcs-7 OBJECT IDENTIFIER ::= { iso(1) member-body(2) US(840) rsadsi(113549) pkcs(1) 7 }
The object identifier for the Data
content type is defined as:
data OBJECT IDENTIFIER ::= { pkcs-7 1 }
which corresponds to the OID string "1.2.840.1.113549.1.7.1".
PKCS#7
specifies the Data
content type as base type without any
cryptographic enhancements:
Data ::= OCTET STRING
Use the Data(byte[] content)
constructor to create a
new Data
object for the given raw data bytes:
byte[] value = ...; Data data = new Data(value);Some applications - for instance some versions of Netscape Navigator - use the indefinite constructed encoding method for generating an octet string that is composed of a certain number of definite primitive encoded octet strings:
0x24 0x80 0x04 <blocksize> <data> 0x04 <blocksize> <data> 0x04 <blocksize> <data> ... 0x00 0x00For being compatible to such applications, this class provides a constructor where a particular blocksize may be specified to give an encoding result as described above:
Data data = new Data(value, blockSize);
In contrast to the stream-variant of the PKCS#7 Data type (implemented by the
DataStream
), where the raw data is
supplied from an input stream and therefore can be read only once, it may be
obtained arbitrarily often from a non-stream Data
object by
utilizing the getData
method.
After transforming a Data
object to an ASN1Object by means of
the toASN1Object
method, it may be parsed back again
by using the Data(ASN1Object obj)
constructor. In
general, the getEncoded
method returns this
Data
object as definite primitive encoded octet string:
0x04 <length> <data>However, if a positive blocksize has been specified when creating this
Data
object, the encoding will be indefinite constructed.
For handling large amounts of data, the parent
DataStream
class should be used.
Content
,
ContentInfo
,
OCTET_STRING
Modifier | Constructor and Description |
---|---|
protected |
Data()
Default constructor for dynamic object creation in ContentInfo.
|
|
Data(ASN1Object obj)
Creates a PKCS#7 Data object from an ASN1Object.
|
|
Data(byte[] content)
Creates a PKCS#7
Data object from a byte array supplying the
data value. |
|
Data(byte[] content,
int blockSize)
Creates a PKCS#7
Data object from a byte array supplying the
data value and a blockSize specifying the encoding scheme. |
|
Data(java.io.InputStream is)
Creates a new PKCS#7 Data from a DER encoded InputStream.
|
Modifier and Type | Method and Description |
---|---|
void |
decode(ASN1Object obj)
Reads and decodes the Data from an ASN1Object.
|
void |
decode(java.io.InputStream is)
Reads and decodes the Data from an InputStream.
|
byte[] |
getData()
Returns a byte array holding the value of this
Data object. |
byte[] |
getEncoded()
Returns the DER encoding of this
Data object as byte array. |
java.io.InputStream |
getInputStream()
Returns an InputStream from which the contents of this object can be read.
|
ASN1Object |
toASN1Object()
Returns this PKCS#7
Data as ASN1Object. |
java.lang.String |
toString(boolean detailed)
Returns a string giving some - if requested - detailed information about
this
Data object. |
getBlockSize, getContentType, setBlockSize, toString, writeTo
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getBlockSize, getContentType, setBlockSize
protected Data()
public Data(byte[] content)
Data
object from a byte array supplying the
data value.
Use this constructor for supplying the content value, e.g.:
Data data = new Data("Test data".getBytes());
content
- the data value in a byte arraypublic Data(byte[] content, int blockSize)
Data
object from a byte array supplying the
data value and a blockSize specifying the encoding scheme. If
blockSize
is not positive this Data object will be encoded as
definite primitive octet string:
0x04 <length> <data>If
blockSize
is positive this Data object will be encoded as
indefinite constructed octet string being composed of a certain number of
definite primitive octet strings of blockSize
length:
0x24 0x80 0x04 <blocksize> <data> 0x04 <blocksize> <data> 0x04 <blocksize> <data> ... 0x00 0x00
content
- the data value in a byte arrayblockSize
- for defining the encoding scheme - and specifying the octet
string component length, if positivepublic Data(ASN1Object obj) throws PKCSParsingException
Data
object, supplied as ASN1Object that may have been created
by calling toASN1Object
.
Use the Data(byte[] content)
constructor for
supplying the content value when creating a Data
object.
obj
- the PKCS#7 Data
as ASN1ObjectPKCSParsingException
- if an parsing error occurspublic Data(java.io.InputStream is) throws java.io.IOException, PKCSParsingException
Data
object, supplied as DER encoding from an input stream.
is
- the input stream supplying the DER encoded Datajava.io.IOException
- if an I/O error occurs during reading from the InputStreamPKCSParsingException
- if an error occurs while parsing the objectpublic void decode(ASN1Object obj) throws PKCSParsingException
decode
in interface Content
obj
- the PKCS#7 Data object as ASN1ObjectPKCSParsingException
- if an error occurs while parsing the objectpublic void decode(java.io.InputStream is) throws java.io.IOException, PKCSParsingException
decode
in interface ContentStream
decode
in class DataStream
is
- the InputStream holding a DER encoded PKCS#7 Data objectjava.io.IOException
- if an I/O error occurs during reading from the InputStreamPKCSParsingException
- if an error occurs while parsing the objectDerInputStream
public byte[] getData()
Data
object.Data
object, as byte arraypublic java.io.InputStream getInputStream()
This method only overrides the corresponding getInputStream
method of the parent DataStream
class
for returning the content of this Data
object. There should be
no real necessity for using this method since the raw data bytes
immediately can be obtained by the getData
method.
However, in contrast to the equivalent getInputStream
method
of the parent DataStream
class, this method may be called
arbitrarily often; it only returns a ByteArrayInputStream that is
initialized with the raw content bytes.
getInputStream
in class DataStream
Data
objectpublic ASN1Object toASN1Object() throws PKCSException
Data
as ASN1Object.
From the internal value an ASN.1 OCTET STRING object is created.toASN1Object
in interface ContentStream
toASN1Object
in class DataStream
Data
as ASN1Object (OCTET_STRING)PKCSException
- if an ASN.1 parsing error occursOCTET_STRING
public byte[] getEncoded() throws PKCSException
Data
object as byte array. In
general, the data is returned as primitive definite encoded octet string:
0x04 <length> <data>However, if a positive blocksize has been specified when creating this
Data
object, the encoding will be indefinite constructed:
0x24 0x80 0x04 <blocksize> <data> 0x04 <blocksize> <data> 0x04 <blocksize> <data> ... 0x00 0x00
PKCSException
- if an encoding error occurspublic java.lang.String toString(boolean detailed)
Data
object.toString
in interface ContentStream
toString
in class DataStream
detailed
- - whether or not to give detailed information