internal static byte[] EncodeX509PublicKey(System.Security.Cryptography.X509Certificates.PublicKey public_key, bool ec_flag) { if (public_key == null) { return(null); } TestKey(public_key.Oid.Value, ec_flag); DerSequence algorithm = new DerSequence(new DerObjectIdentifier(public_key.Oid.Value)); Asn1StreamParser asp = new Asn1StreamParser(public_key.EncodedParameters.RawData); IAsn1Convertible ro; while ((ro = asp.ReadObject()) != null) { algorithm.AddObject(ro.ToAsn1Object()); } return(new DerSequence(algorithm, new DerBitString(public_key.EncodedKeyValue.RawData)).GetEncoded()); }