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.
-
DER
- Global value for ASN.1 coding format DER.
-
PEM
- Global value for ASN.1 coding format PEM.
-
startLine
- First line of a file in PEM format.
-
ASN1()
- Default constructor.
-
ASN1(ASN1Object)
- Creates an ASN1 object from the internal ASN1Object representation.
-
ASN1(byte[])
- Creates an ASN1Object from a byte array.
-
ASN1(InputStream)
- Creates an ASN1 object from an InputStream.
-
ASN1(String)
- Creates an ASN1 object from a file.
-
countComponents()
- Returns the number of components in this ASN1Object.
-
fingerprint()
- Returns a fingerprint (MD5 Hash of the whole ASN1Object).
-
getComponentAt(int)
- Returns the ASN1Object at index if the ASN1Object is a SEQUENCE.
-
getFirstObject()
- Returns the first object of the first sequence.
-
saveFormat()
- Returns the file format: ASN1.DER, ASN1.PEM.
-
saveToFile(String)
- Saves the ASN1Object to a DER file.
-
saveToFile(String, String, String)
- Saves the ASN1Object to a PEM file.
-
toASN1Object()
- Returns the ASN1Object.
-
toByteArray(int)
- Returns the ASN1Object in DER format.
-
toString()
- Returns a string that represents the contents of this ASN1Object.
DER
public static final int DER
- Global value for ASN.1 coding format DER.
PEM
public static final int PEM
- Global value for ASN.1 coding format PEM.
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.
ASN1
public ASN1()
- Default constructor. Creates an empty object.
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
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
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
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
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
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()
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
toByteArray
public byte[] toByteArray(int format)
- Returns the ASN1Object in DER format.
- Returns:
- the ASN1Object in DER format
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
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
saveFormat
public int saveFormat()
- Returns the file format: ASN1.DER, ASN1.PEM.
- Returns:
- the file format
toString
public String toString()
- Returns a string that represents the contents of this ASN1Object.
- Returns:
- the string representation
- Overrides:
- toString in class Object
toASN1Object
public ASN1Object toASN1Object()
- Returns the ASN1Object.
- Returns:
- the ASN1Object
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