Ejemplo n.º 1
0
        public void SaveToFile(int fileIndex)
        {
            string fileName    = string.Format(ARCHIVE_FILE_NAME, fileIndex);
            string sFolderPath = Application.persistentDataPath + "/" + ARCHIVE_FILE_DIR;

            if (!Directory.Exists(sFolderPath))
            {
                Directory.CreateDirectory(sFolderPath);
            }
            string sPath = sFolderPath + "/" + fileName;

            using (MemoryStream ms = new MemoryStream())
            {
                //写入存档内容
                TDES tdesTool = new TDES();
                tdesTool.Init(ConStr.DES_KEY);

                Hashtable hsData       = Save();
                byte[]    strBuffer    = System.Text.Encoding.Default.GetBytes(hsData.toJson());
                byte[]    encryptDatas = tdesTool.Encrypt(strBuffer);
                ms.Write(BitConverter.GetBytes(encryptDatas.Length), 0, sizeof(int));
                ms.Write(encryptDatas, 0, encryptDatas.Length);

                File.WriteAllBytes(sPath, ms.GetBuffer());
            }
        }
Ejemplo n.º 2
0
        void MessageReceivedCallback(SocketIOHandler socket, JSONObject message)
        {
            NetUtil.Log(socket.IpAddress + ": " + message.ToString());

            if (authenticateUserCallback != null)
            {
                JSONObject response = authenticateUserCallback.Invoke(message.GetString("username"), message.GetString("password"));
                if (useTDES)
                {
                    Send(socket, Convert.ToBase64String(TDES.Encrypt(message.GetString("key"), response.ToString())));
                }
                else
                {
                    Send(socket, response.ToString());
                }
            }
        }
Ejemplo n.º 3
0
 public static string Encrypt(Algorithm algorithm, string symmetricKey, string message, out string IV)
 {
     if (algorithm == Algorithm.AES)
     {
         return(AES.Encrypt(symmetricKey, message, out IV));
     }
     else if (algorithm == Algorithm.RIJ)
     {
         return(RIJ.Encrypt(symmetricKey, message, out IV));
     }
     else if (algorithm == Algorithm.DES)
     {
         return(TDES.Encrypt(symmetricKey, message, out IV));
     }
     else
     {
         IV = string.Empty;
         return("Algorithm Issue");
     }
 }