Exemple #1
0
 /// <summary>
 /// 对文件主体加入暗号类型+暗号+数据标签
 /// </summary>
 /// <param name="date">数据</param>
 /// <param name="sendDateLabel">标签</param>
 /// <returns>加密之后的数据(暗号类型+暗号+数据标签)</returns>
 private static byte[] SendSubjectEncryption(byte[] date, int sendDateLabel)
 {
     byte[] dateOverall = ByteToDate.OffsetEncryption(date, sendDateLabel, 2);
     dateOverall[0] = CipherCode._bigDateCode;
     dateOverall[1] = CipherCode._fileSubjectCode;
     return(dateOverall);
 }
Exemple #2
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(CipherCode._sendUser, CipherCode._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(EncDecFile.FileSevenEncryption(CipherCode._sendUser, CipherCode._fileCancel, fileSend.FileLabel)); }
            if (haveDatelenth <= 0)
            {
                return(null); //说明数据发完了,文件会到外面去关掉
            }
            fileSend.FileOkLenth = fileSend.FileOkLenth + haveDatelenth;
            dateOverall          = ByteToDate.OffsetEncryption(haveDate, fileSend.FileLabel, 3);
            dateOverall[0]       = CipherCode._fileCode;
            dateOverall[1]       = CipherCode._sendUser;
            dateOverall[2]       = CipherCode._fileSubjectCode;
            return(dateOverall);
        }
Exemple #3
0
 /// <summary>
 /// 对数据加入暗号与数据标签
 /// </summary>
 /// <param name="date">要加密的数据</param>
 /// <param name="textCode">数据模型的暗号</param>
 /// <param name="state">StateBase</param>
 /// <returns>加密之后的数据(1暗号+1暗号+4数据标签+date)</returns>
 private static byte[] encryptionTemporary(byte[] date, byte textCode, TransmitData state)
 {
     if (date.Length > state.BufferSize - 20)
     {
         //超出通过文件大数据包处理发送
         return(EncDecSeparateDate.SendHeadEncryption(date, textCode, state));
     }
     //给发送的数据进行编号
     state.SendDateLabel = RandomPublic.RandomNumber(16787);
     //编号并加密 (加密
     byte[] dateOverall = ByteToDate.OffsetEncryption(date, state.SendDateLabel, 2);
     dateOverall[0] = CipherCode._commonCode;
     dateOverall[1] = textCode;
     return(dateOverall);
 }