Exemplo n.º 1
0
        /// <summary>
        /// Check if a file is PEM formated.
        /// </summary>
        /// <param name="fileName">source file name.</param>
        /// <returns>true:Yes, false:No.</returns>
        public static bool IsPemFormatedFile(string fileName)
        {
            bool retval = false;

            try
            {
                FileStream fs   = new FileStream(fileName, System.IO.FileMode.Open);
                byte[]     data = new byte[fs.Length];
                fs.Read(data, 0, data.Length);
                fs.Close();
                string dataStr = Asn1Util.BytesToString(data);
                retval = IsPemFormated(dataStr);
            }
            catch
            {
                retval = false;
            }
            return(retval);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Load PEM formated file.
        /// </summary>
        /// <param name="fileName">PEM file name.</param>
        public void LoadPemData(string fileName)
        {
            FileStream fs = new FileStream(fileName, FileMode.Open);

            byte[] data = new byte[fs.Length];
            fs.Read(data, 0, data.Length);
            fs.Close();
            string dataStr = Asn1Util.BytesToString(data);

            if (Asn1Util.IsPemFormated(dataStr))
            {
                Stream ms = Asn1Util.PemToStream(dataStr);
                ms.Position = 0;
                LoadData(ms);
            }
            else
            {
                throw new Exception("It is a invalid PEM file: " + fileName);
            }
        }