示例#1
0
    public static string EncryptFile(string filePath)
    {
        Debug.Log("Encrypting");
        var output = String.Empty;
        try
        {
            using (RijndaelManaged aes = new RijndaelManaged())
            {
                byte[] key = ASCIIEncoding.UTF8.GetBytes(skey);

                byte[] IV = ASCIIEncoding.UTF8.GetBytes(vkey);

                using (FileStream fsCrypt = new FileStream(filePath + "uSave.dat", FileMode.Create))
                {
                    using (ICryptoTransform encryptor = aes.CreateEncryptor(key, IV))
                    {
                        using (CryptoStream cs = new CryptoStream(fsCrypt, encryptor, CryptoStreamMode.Write))
                        {
                            using (FileStream fsIn = new FileStream(filePath + "eSave.dat", FileMode.Open))
                            {
                                int data;

                                while ((data = fsIn.ReadByte()) != -1)
                                {
                                    cs.WriteByte((byte)data);
                                }
                                output = cs.ToString();
                            }
                        }
                    }
                }
            }
            //File.Delete(filePath + "uSave.dat");
        }
        catch{} // failed to encrypt file

        return output;
    }