static IPrivateKey DecodePrivateKey(string fname) { byte[] buf = File.ReadAllBytes(fname); PEMObject[] fpo = AsnIO.DecodePEM(buf); if (fpo.Length == 0) { buf = AsnIO.FindBER(buf); } else { buf = null; foreach (PEMObject po in fpo) { string tt = po.type.ToUpperInvariant(); if (tt.IndexOf("PRIVATE KEY") >= 0) { if (buf != null) { throw new Exception( "Multiple keys in '" + fname + "'"); } buf = po.data; } } } if (buf == null) { throw new Exception(string.Format( "No private key in file '{0}'", fname)); } return(KF.DecodePrivateKey(buf)); }