Exemplo n.º 1
0
        /// <summary>
        /// 对文件主体进行加密
        /// </summary>
        /// <param name="fileSend">FileState</param>
        /// <param name="bufferSize">缓冲区大小</param>
        /// <returns>加密之后数据</returns>
        internal static byte[] FileSubjectEncryption(FileState fileSend, int bufferSize)
        {
            byte[] dateOverall = null;
            if (fileSend.StateFile == 2)//说明我这里已经暂停了;要发一个暂停的消息给对方
            {
                dateOverall = FileSevenEncryption(PasswordCode._sendUser, PasswordCode._sendStop, fileSend.FileLabel);
                return(dateOverall);
            }
            int BufferSize = bufferSize - 24;

            if (fileSend.FileLenth - fileSend.FileOkLenth < BufferSize)
            {
                BufferSize = (int)(fileSend.FileLenth - fileSend.FileOkLenth);
            }
            byte[] haveDate      = new byte[BufferSize];
            int    haveDatelenth = 1;

            try
            {
                haveDatelenth = fileSend.Filestream.Read(haveDate, 0, BufferSize);
            }//异常说明这个文件已经被我方取消掉;返回一个取消信息给对方
            catch { return(EncryptionDecryptFile.FileSevenEncryption(PasswordCode._sendUser, PasswordCode._fileCancel, fileSend.FileLabel)); }
            if (haveDatelenth <= 0)
            {
                return(null); //说明数据发完了,文件会到外面去关掉
            }
            fileSend.FileOkLenth = fileSend.FileOkLenth + haveDatelenth;
            dateOverall          = ByteToDate.OffsetEncryption(haveDate, fileSend.FileLabel, 3);
            dateOverall[0]       = PasswordCode._fileCode;
            dateOverall[1]       = PasswordCode._sendUser;
            dateOverall[2]       = PasswordCode._fileSubjectCode;
            return(dateOverall);
        }
Exemplo n.º 2
0
 /// <summary>
 /// 对文件主体进行解密;
 /// </summary>
 /// <param name="fileSend"></param>
 /// <param name="receiveDate"></param>
 /// <returns></returns>
 internal static byte[] FileSubjectDecrypt(FileState fileSend, byte[] receiveDate)
 {
     byte[] haveDate = null;
     if (fileSend.StateFile == 2)//说明我这里已经暂停了;要发一个暂停的消息给对方
     {
         return(FileSevenEncryption(PasswordCode._receiveUser, PasswordCode._sendStop, fileSend.FileLabel));
     }
     haveDate = new byte[receiveDate.Length - 7];
     Array.Copy(receiveDate, 7, haveDate, 0, haveDate.Length);
     try
     {
         fileSend.Filestream.Write(haveDate, 0, haveDate.Length);
     }//异常说明这个文件已经被我方取消掉;返回一个取消信息给对方
     catch { return(EncryptionDecryptFile.FileSevenEncryption(PasswordCode._receiveUser, PasswordCode._fileCancel, fileSend.FileLabel)); }
     fileSend.FileOkLenth = fileSend.FileOkLenth + haveDate.Length;
     haveDate             = FileSevenEncryption(PasswordCode._receiveUser, PasswordCode._dateSuccess, fileSend.FileLabel);
     return(haveDate);
 }