Beispiel #1
0
        /// <summary>Reads all bytes into memory and removes PGP armor if present.</summary>
        public byte[] GetBytes(string sFilePath, bool isKey)
        {
            bool isAscii = true;

            byte[]   abReturn = null;
            byte[]   abBuffer = new byte[0x1000];
            int      i, iBytesRead;
            string   sArmorString;
            PgpArmor Armor;

            // read the file into an array of bytes in working memory
            using (FileStream PgpFileStream = new FileStream(sFilePath, FileMode.Open, FileAccess.Read))
            {
                using (MemoryStream PgpMemoryStream = new MemoryStream())
                {
                    while ((iBytesRead = PgpFileStream.Read(abBuffer, 0, abBuffer.Length)) > 0)
                    {
                        PgpMemoryStream.Write(abBuffer, 0, iBytesRead);
                    }
                    abReturn = PgpMemoryStream.ToArray();
                }
            }

            if (abReturn != null)
            {
                _eStatus = PgpArmor.nStatus.OK;

                for (i = 0; i < abReturn.Length; i++)
                {
                    isAscii = isAscii && ((abReturn[i] & 0x80) == 0);
                }

                if (isAscii)
                {
                    Armor        = new PgpArmor();
                    sArmorString = Encoding.ASCII.GetString(abReturn);
                    abReturn     = Armor.Parse(sArmorString, isKey);
                    _eStatus     = Armor.eStatus;
                }
            }

            return(abReturn);
        }
Beispiel #2
0
 public PgpFile()
 {
     _eStatus = PgpArmor.nStatus.Undefined;
 }