Decoding ASN.1 in C#



  • I've been working with C# for the last 3 months. I've been able to guide myself with only the online C# reference from MSFT, but I've just ran into a brick wall. I need to get the public key parameters from an X509 Certificate, and the functions return an ASN.1 encoded byte array. I wouldn't usually worry about this... except that the only class I've found that can decode this data (<FONT size=2 face="Courier New"><FONT size=2 face="Courier New">System.Security.Cryptography.</FONT></FONT><FONT color=#2b91af size=2 face="Courier New"><FONT color=#2b91af size=2 face="Courier New"><FONT color=#2b91af size=2 face="Courier New">AsnEncodedData</FONT></FONT></FONT>) doesn't have any methods to extract the actual data. It has a useful .Format() function, which will show me the hex bytes for each attribute, but this is useless to me as what I want is the actual values.

    <FONT color=#2b91af size=2 face="Courier New"><FONT color=#2b91af size=2 face="Courier New"><FONT color=#2b91af size=2 face="Courier New"><FONT color=#000000 face=Arial>Is there some .NET framework class that does this?</FONT>

    </FONT></FONT></FONT>


  • I've not used it before, but the AsnEncodedData class has a RawData property which might do what you want...

    "A byte array that represents the Abstract Syntax Notation One (ASN.1)-encoded data."
    http://msdn.microsoft.com/en-us/library/system.security.cryptography.asnencodeddata.rawdata.aspx


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.