Esempio n. 1
0
        public void LoadPemData(string fileName)
        {
            FileStream fileStream = new FileStream(fileName, FileMode.Open);

            byte[] numArray = new byte[fileStream.Length];
            fileStream.Read(numArray, 0, numArray.Length);
            fileStream.Close();
            string pemStr = Asn1Util.BytesToString(numArray);

            if (!Asn1Util.IsPemFormated(pemStr))
            {
                throw new Exception("It is a invalid PEM file: " + fileName);
            }
            Stream stream = Asn1Util.PemToStream(pemStr);

            stream.Position = 0L;
            this.LoadData(stream);
        }
Esempio 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);
            }
        }