예제 #1
0
        public static string Decrypt(string path)
        {
            CryptoKeyData keyData = GetKeyData(Path.GetFileName(path));

            byte[] input  = File.ReadAllBytes(path);
            byte[] output = new byte[input.Length];

            Aes128CounterMode aes = new Aes128CounterMode(keyData.IV);
            ICryptoTransform  ict = aes.CreateEncryptor(keyData.Key, null);

            ict.TransformBlock(input, 0, input.Length, output, 0);
            return(Encoding.ASCII.GetString(output));
        }
예제 #2
0
        public static void Encrypt(string path, string contents)
        {
            CryptoKeyData keyData = GetKeyData(Path.GetFileName(path));

            byte[] input  = Encoding.ASCII.GetBytes(contents);
            byte[] output = new byte[input.Length];

            Aes128CounterMode aes = new Aes128CounterMode(keyData.IV);
            ICryptoTransform  ict = aes.CreateEncryptor(keyData.Key, null);

            ict.TransformBlock(input, 0, input.Length, output, 0);

            File.WriteAllBytes(path, output);
        }