All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class iaik.asn1.ASN1

java.lang.Object
   |
   +----iaik.asn1.ASN1

public class ASN1
extends Object
This class is responsible for converting ASN.1 objects between internal (ASN1Object) and external (PEM, DER encoded arrays) representation.


Variable Index

 o DER
Global value for ASN.1 coding format DER.
 o PEM
Global value for ASN.1 coding format PEM.
 o startLine
First line of a file in PEM format.

Constructor Index

 o ASN1()
Default constructor.
 o ASN1(ASN1Object)
Creates an ASN1 object from the internal ASN1Object representation.
 o ASN1(byte[])
Creates an ASN1Object from a byte array.
 o ASN1(InputStream)
Creates an ASN1 object from an InputStream.
 o ASN1(String)
Creates an ASN1 object from a file.

Method Index

 o countComponents()
Returns the number of components in this ASN1Object.
 o fingerprint()
Returns a fingerprint (MD5 Hash of the whole ASN1Object).
 o getComponentAt(int)
Returns the ASN1Object at index if the ASN1Object is a SEQUENCE.
 o getFirstObject()
Returns the first object of the first sequence.
 o saveFormat()
Returns the file format: ASN1.DER, ASN1.PEM.
 o saveToFile(String)
Saves the ASN1Object to a DER file.
 o saveToFile(String, String, String)
Saves the ASN1Object to a PEM file.
 o toASN1Object()
Returns the ASN1Object.
 o toByteArray(int)
Returns the ASN1Object in DER format.
 o toString()
Returns a string that represents the contents of this ASN1Object.

Variables

 o DER
 public static final int DER
Global value for ASN.1 coding format DER.

 o PEM
 public static final int PEM
Global value for ASN.1 coding format PEM.

 o startLine
 public static String startLine
First line of a file in PEM format. ASN(String fileName) first tries to find a line which starts with startLine and then reads the following ASN.1 object.

Constructors

 o ASN1
 public ASN1()
Default constructor. Creates an empty object.

 o ASN1
 public ASN1(ASN1Object obj) throws CodingException
Creates an ASN1 object from the internal ASN1Object representation.

Parameters:
obj - the ASN1Object
Throws: CodingException
if the ASN1Object could not be DER encoded
 o ASN1
 public ASN1(String fileName) throws IOException, CodingException
Creates an ASN1 object from a file. The format of the file could be PEM or DER. If the format is PEM the ASN1. object following the startLine is read from the file.

Parameters:
fileName - the name of the file
Throws: IOException
if there is a problem with the file
Throws: CodingException
if the object could not be decoded
 o ASN1
 public ASN1(InputStream is) throws IOException, CodingException
Creates an ASN1 object from an InputStream. The data can be in DER or PEM format. To decide if the data is DER or PEM encoded this method uses the first byte of data: If the first byte has the value: 65-77, 103-122 the format is PEM. Otherwise the format is DER. DER uses the tags 1-24, 48, 49, and 128-. These values PEM encoded result in (65-77, 103-122) and thats why the algorithm should work :).

Parameters:
is - the InputStream containing the data
Throws: IOException
if there is a problem with the InputStream
Throws: CodingException
if the object could not be decoded
 o ASN1
 public ASN1(byte array[]) throws CodingException
Creates an ASN1Object from a byte array. The format of the array could be PEM or DER.

Parameters:
array - the byte array containing the object
Throws: CodingException
if the object could not be decoded

Methods

 o getComponentAt
 public ASN1Object getComponentAt(int index) throws CodingException
Returns the ASN1Object at index if the ASN1Object is a SEQUENCE.

Parameters:
index - position in the sequence
Returns:
the ASN1Object at this position
Throws: CodingException
if this ASN1Object does not support getComponentAt(int) or to indicate that the index is illegal
 o countComponents
 public int countComponents() throws CodingException
Returns the number of components in this ASN1Object. Only useful with a SEQUENCE.

Returns:
the number of components in this ASN1Object
Throws: CodingException
if this ASN1Object does not support countComponents()
 o getFirstObject
 public byte[] getFirstObject() throws CodingException
Returns the first object of the first sequence. To get the signed data from the original data. Otherwise the signature could be different.

Returns:
the data of the (signed) first object
Throws: CodingException
if there is no first object
 o toByteArray
 public byte[] toByteArray(int format)
Returns the ASN1Object in DER format.

Returns:
the ASN1Object in DER format
 o saveToFile
 public void saveToFile(String fileName) throws IOException
Saves the ASN1Object to a DER file.

Parameters:
fileName - the name of the file
Throws: IOException
if there is a problem with the file
 o saveToFile
 public void saveToFile(String fileName,
                        String begin,
                        String end) throws IOException
Saves the ASN1Object to a PEM file.

Parameters:
fileName - the name of the file
begin - the first line of the file
end - the last line of the file
Throws: IOException
if there is a problem with the file
 o saveFormat
 public int saveFormat()
Returns the file format: ASN1.DER, ASN1.PEM.

Returns:
the file format
 o toString
 public String toString()
Returns a string that represents the contents of this ASN1Object.

Returns:
the string representation
Overrides:
toString in class Object
 o toASN1Object
 public ASN1Object toASN1Object()
Returns the ASN1Object.

Returns:
the ASN1Object
 o fingerprint
 public byte[] fingerprint()
Returns a fingerprint (MD5 Hash of the whole ASN1Object).

Returns:
the fingerprint

All Packages  Class Hierarchy  This Package  Previous  Next  Index