The general procedure to decode an ASN.1 MDER message involves the following three steps:
Create a decode buffer on the message to be decoded
Invoke the decode method
Process the decoded data values
The first step is the creation of a decode buffer. Asn1MderDecodeBuffer has a constructor that accepts messages stored in a byte array. It also has a constructor that accepts a System.IO.Stream so that messages may be streamed from various sources, such as from a file.
The second step is to invoke the generated decode method. The calling arguments were described earlier.
The final step is to apply your application-specific processing to the data. All data is contained within public member variables so access is quite easy.
A complete example showing how to invoke a decode method is as follows:
try { // Step 1: create a decode buffer for the message to be decoded. // This example will use a file input stream to decode a message // in a binary file. // Create an input file stream object Stream ins = File.OpenRead( filename ); // Create a decode buffer object Asn1MderDecodeBuffer decodeBuffer = new Asn1MderDecodeBuffer (ins); // Step 2: create an object of the generated type and invoke the // decode method.. PersonnelRecord personnelRecord = new PersonnelRecord (); personnelRecord.Decode (decodeBuffer); // Step 3: process the data if (trace) { System.Console.Out.WriteLine ("Decode was successful"); personnelRecord.Print ("personnelRecord"); } } catch (Exception e) { System.Console.Out.WriteLine (e.Message); Asn1Util.WriteStackTrace(e, Console.Error); return; }