Sylloge
A C# helper library
code/Encryption/Aes.cs
Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 using System.Security.Cryptography;
00017 namespace Sylloge.Encryption
00018 {
00022     public static class Aes
00023     {
00027         public const int BlockSize = 256;
00031         public const int KeySize = 256;
00032 
00037         public class EncryptStream : Sylloge.Encryption.BinaryStream
00038         {
00044             public EncryptStream(string pass, byte[] salt)
00045                 : base(AlgorithmType.AES_Rijndael, StreamType.Encrypt, Aes.BlockSize, Aes.KeySize, pass, salt)
00046             { }
00047 
00054             public EncryptStream(string pass, byte[] salt, CryptoStreamMode mode)
00055                 : base(AlgorithmType.AES_Rijndael, StreamType.Encrypt, Aes.BlockSize, Aes.KeySize, pass, salt, mode)
00056             { }
00057 
00065             public EncryptStream(string pass, byte[] salt, int blockSize, int keySize)
00066                 : base(AlgorithmType.AES_Rijndael, StreamType.Encrypt, blockSize, keySize, pass, salt)
00067             { }
00068 
00077             public EncryptStream(string pass, byte[] salt, int blockSize, int keySize, CryptoStreamMode mode)
00078                 : base(AlgorithmType.AES_Rijndael, StreamType.Encrypt, blockSize, keySize, pass, salt, mode)
00079             { }
00080 
00086             public EncryptStream(byte[] key, byte[] iv)
00087                 : base(AlgorithmType.AES_Rijndael, StreamType.Encrypt, Aes.BlockSize, Aes.KeySize, key, iv)
00088             { }
00089 
00096             public EncryptStream(byte[] key, byte[] iv, CryptoStreamMode mode)
00097                 : base(AlgorithmType.AES_Rijndael, StreamType.Encrypt, Aes.BlockSize, Aes.KeySize, key, iv, mode)
00098             { }
00099 
00107             public EncryptStream(byte[] key, byte[] iv, int blockSize, int keySize)
00108                 : base(AlgorithmType.AES_Rijndael, StreamType.Encrypt, blockSize, keySize, key, iv)
00109             { }
00110 
00119             public EncryptStream(byte[] key, byte[] iv, int blockSize, int keySize, CryptoStreamMode mode)
00120                 : base(AlgorithmType.AES_Rijndael, StreamType.Encrypt, blockSize, keySize, key, iv, mode)
00121             { }
00122         }
00123 
00128         public class DecryptStream : Sylloge.Encryption.BinaryStream
00129         {
00135             public DecryptStream(string pass, byte[] salt)
00136                 : base(AlgorithmType.AES_Rijndael, StreamType.Decrypt, Aes.BlockSize, Aes.KeySize, pass, salt)
00137             { }
00138 
00145             public DecryptStream(string pass, byte[] salt, CryptoStreamMode mode)
00146                 : base(AlgorithmType.AES_Rijndael, StreamType.Decrypt, Aes.BlockSize, Aes.KeySize, pass, salt, mode)
00147             { }
00148 
00156             public DecryptStream(string pass, byte[] salt, int blockSize, int keySize)
00157                 : base(AlgorithmType.AES_Rijndael, StreamType.Decrypt, blockSize, keySize, pass, salt)
00158             { }
00159 
00168             public DecryptStream(string pass, byte[] salt, int blockSize, int keySize, CryptoStreamMode mode)
00169                 : base(AlgorithmType.AES_Rijndael, StreamType.Decrypt, blockSize, keySize, pass, salt, mode)
00170             { }
00171 
00177             public DecryptStream(byte[] key, byte[] iv)
00178                 : base(AlgorithmType.AES_Rijndael, StreamType.Decrypt, Aes.BlockSize, Aes.KeySize, key, iv)
00179             { }
00180 
00187             public DecryptStream(byte[] key, byte[] iv, CryptoStreamMode mode)
00188                 : base(AlgorithmType.AES_Rijndael, StreamType.Decrypt, Aes.BlockSize, Aes.KeySize, key, iv, mode)
00189             { }
00190 
00198             public DecryptStream(byte[] key, byte[] iv, int blockSize, int keySize)
00199                 : base(AlgorithmType.AES_Rijndael, StreamType.Decrypt, blockSize, keySize, key, iv)
00200             { }
00201 
00210             public DecryptStream(byte[] key, byte[] iv, int blockSize, int keySize, CryptoStreamMode mode)
00211                 : base(AlgorithmType.AES_Rijndael, StreamType.Decrypt, blockSize, keySize, key, iv, mode)
00212             { }
00213         }
00214 
00226         public static byte[] Decrypt(byte[] cipherData, byte[] key, byte[] iv, int blockSize, int keySize)
00227         {
00228             Aes.DecryptStream ds = new DecryptStream(key, iv, blockSize, keySize);
00229             ds.Write(cipherData);
00230             return ds.ToArray();
00231         }
00232 
00242         public static byte[] Decrypt(byte[] cipherData, byte[] key, byte[] iv)
00243         {
00244             Aes.DecryptStream ds = new DecryptStream(key, iv);
00245             ds.Write(cipherData);
00246             return ds.ToArray();
00247         }
00248 
00259         public static byte[] Decrypt(byte[] cipherData, string pass, byte[] salt, int blockSize, int keySize)
00260         {
00261             Aes.DecryptStream ds = new DecryptStream(pass, salt, blockSize, keySize);
00262             ds.Write(cipherData);
00263             return ds.ToArray();
00264         }
00265 
00274         public static byte[] Decrypt(byte[] cipherData, string pass, byte[] salt)
00275         {
00276             Aes.DecryptStream ds = new DecryptStream(pass, salt);
00277             ds.Write(cipherData);
00278             return ds.ToArray();
00279         }
00280 
00292         public static byte[] Encrypt(byte[] clearData, byte[] key, byte[] iv, int blockSize, int keySize)
00293         {
00294             Aes.EncryptStream es = new EncryptStream(key, iv, blockSize, keySize);
00295             es.Write(clearData);
00296             return es.ToArray();
00297         }
00298 
00308         public static byte[] Encrypt(byte[] clearData, byte[] key, byte[] iv)
00309         {
00310             Aes.EncryptStream es = new EncryptStream(key, iv);
00311             es.Write(clearData);
00312             return es.ToArray();
00313         }
00314 
00325         public static byte[] Encrypt(byte[] clearData, string pass, byte[] salt, int blockSize, int keySize)
00326         {
00327             Aes.EncryptStream es = new EncryptStream(pass, salt, blockSize, keySize);
00328             es.Write(clearData);
00329             return es.ToArray();
00330         }
00331 
00340         public static byte[] Encrypt(byte[] clearData, string pass, byte[] salt)
00341         {
00342             Aes.EncryptStream es = new EncryptStream(pass, salt);
00343             es.Write(clearData);
00344             return es.ToArray();
00345         }
00346     }
00347 }
 All Classes Namespaces Files Functions Variables Enumerations Properties Events