Sylloge
A C# helper library
code/Encryption/TripleDES.cs
Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 using System;
00018 using System.Collections.Generic;
00019 using System.Text;
00020 using System.Windows.Forms;
00021 using System.Security.Cryptography;
00022 
00023 namespace Sylloge.Encryption
00024 {
00028     public static class TripleDES
00029     {
00033         public const int BlockSize = 64;
00037         public const int KeySize = 64;
00038 
00043         public class EncryptStream : Sylloge.Encryption.BinaryStream
00044         {
00050             public EncryptStream(string pass, byte[] salt)
00051                 : base(AlgorithmType.TripleDES, StreamType.Encrypt, TripleDES.BlockSize, TripleDES.KeySize, pass, salt)
00052             { }
00053 
00060             public EncryptStream(string pass, byte[] salt, CryptoStreamMode mode)
00061                 : base(AlgorithmType.TripleDES, StreamType.Encrypt, TripleDES.BlockSize, TripleDES.KeySize, pass, salt, mode)
00062             { }
00063 
00071             public EncryptStream(string pass, byte[] salt, int blockSize, int keySize)
00072                 : base(AlgorithmType.TripleDES, StreamType.Encrypt, blockSize, keySize, pass, salt)
00073             { }
00074 
00083             public EncryptStream(string pass, byte[] salt, int blockSize, int keySize, CryptoStreamMode mode)
00084                 : base(AlgorithmType.TripleDES, StreamType.Encrypt, blockSize, keySize, pass, salt, mode)
00085             { }
00086 
00092             public EncryptStream(byte[] key, byte[] iv)
00093                 : base(AlgorithmType.TripleDES, StreamType.Encrypt, TripleDES.BlockSize, TripleDES.KeySize, key, iv)
00094             { }
00095 
00102             public EncryptStream(byte[] key, byte[] iv, CryptoStreamMode mode)
00103                 : base(AlgorithmType.TripleDES, StreamType.Encrypt, TripleDES.BlockSize, TripleDES.KeySize, key, iv, mode)
00104             { }
00105 
00113             public EncryptStream(byte[] key, byte[] iv, int blockSize, int keySize)
00114                 : base(AlgorithmType.TripleDES, StreamType.Encrypt, blockSize, keySize, key, iv)
00115             { }
00116 
00125             public EncryptStream(byte[] key, byte[] iv, int blockSize, int keySize, CryptoStreamMode mode)
00126                 : base(AlgorithmType.TripleDES, StreamType.Encrypt, blockSize, keySize, key, iv, mode)
00127             { }
00128         }
00129 
00134         public class DecryptStream : Sylloge.Encryption.BinaryStream
00135         {
00141             public DecryptStream(string pass, byte[] salt)
00142                 : base(AlgorithmType.TripleDES, StreamType.Decrypt, TripleDES.BlockSize, TripleDES.KeySize, pass, salt)
00143             { }
00144 
00151             public DecryptStream(string pass, byte[] salt, CryptoStreamMode mode)
00152                 : base(AlgorithmType.TripleDES, StreamType.Decrypt, TripleDES.BlockSize, TripleDES.KeySize, pass, salt, mode)
00153             { }
00154 
00162             public DecryptStream(string pass, byte[] salt, int blockSize, int keySize)
00163                 : base(AlgorithmType.TripleDES, StreamType.Decrypt, blockSize, keySize, pass, salt)
00164             { }
00165 
00174             public DecryptStream(string pass, byte[] salt, int blockSize, int keySize, CryptoStreamMode mode)
00175                 : base(AlgorithmType.TripleDES, StreamType.Decrypt, blockSize, keySize, pass, salt, mode)
00176             { }
00177 
00183             public DecryptStream(byte[] key, byte[] iv)
00184                 : base(AlgorithmType.TripleDES, StreamType.Decrypt, TripleDES.BlockSize, TripleDES.KeySize, key, iv)
00185             { }
00186 
00193             public DecryptStream(byte[] key, byte[] iv, CryptoStreamMode mode)
00194                 : base(AlgorithmType.TripleDES, StreamType.Decrypt, TripleDES.BlockSize, TripleDES.KeySize, key, iv, mode)
00195             { }
00196 
00204             public DecryptStream(byte[] key, byte[] iv, int blockSize, int keySize)
00205                 : base(AlgorithmType.TripleDES, StreamType.Decrypt, blockSize, keySize, key, iv)
00206             { }
00207 
00216             public DecryptStream(byte[] key, byte[] iv, int blockSize, int keySize, CryptoStreamMode mode)
00217                 : base(AlgorithmType.TripleDES, StreamType.Decrypt, blockSize, keySize, key, iv, mode)
00218             { }
00219         }
00220 
00228         public static byte[] Decrypt(byte[] cipherData, byte[] key, byte[] iv)
00229         {
00230             TripleDES.DecryptStream es = new DecryptStream(key, iv);
00231             es.Write(cipherData);
00232             return es.ToArray();
00233         }
00234 
00242         public static byte[] Decrypt(byte[] cipherData, string pass, byte[] salt)
00243         {
00244             TripleDES.DecryptStream es = new DecryptStream(pass, salt);
00245             es.Write(cipherData);
00246             return es.ToArray();
00247         }
00248 
00256         public static byte[] Encrypt(byte[] clearData, byte[] key, byte[] iv)
00257         {
00258             TripleDES.EncryptStream es = new EncryptStream(key, iv);
00259             es.Write(clearData);
00260             return es.ToArray();
00261         }
00262 
00270         public static byte[] Encrypt(byte[] clearData, string pass, byte[] salt)
00271         {
00272             TripleDES.EncryptStream es = new EncryptStream(pass, salt);
00273             es.Write(clearData);
00274             return es.ToArray();
00275         }
00276     }
00277 }
 All Classes Namespaces Files Functions Variables Enumerations Properties Events