Esempio n. 1
0
        public static ICryptoValue Encrypt(DesTypes type, byte[] originalBytes, byte[] pwd, byte[] iv, byte[] salt)
        {
            var key      = Factory.GenerateKey(type, pwd, iv);
            var function = Factory.Create(type, key);

            return(function.Encrypt(originalBytes, salt));
        }
        public static DesKey Generate(DesTypes type)
        {
            switch (type)
            {
            case DesTypes.DES:
            {
                using var provider = new DESCryptoServiceProvider();
                return(new DesKey(DesTypes.DES, provider.Key, provider.IV));
            }

            case DesTypes.TripleDES128:
            {
                using var provider = new TripleDESCryptoServiceProvider();
                return(new DesKey(DesTypes.TripleDES128, provider.Key, provider.IV));
            }

            case DesTypes.TripleDES192:
            {
                using var provider = new TripleDESCryptoServiceProvider();
                return(new DesKey(DesTypes.TripleDES192, provider.Key, provider.IV));
            }

            default:
                throw new ArgumentException("The length of the key is invalid.");
            }
        }
Esempio n. 3
0
 public DesKey(DesTypes type, string pwd, string iv, Encoding encoding = null)
 {
     encoding = encoding.SafeEncodingValue();
     Size     = (int)type;
     Key      = encoding.SafeEncodingValue().GetBytes(pwd);
     IV       = encoding.SafeEncodingValue().GetBytes(iv);
 }
Esempio n. 4
0
        public static ICryptoValue Decrypt(DesTypes type, byte[] cipherBytes, byte[] pwd, byte[] iv, byte[] salt)
        {
            var key      = Factory.GenerateKey(type, pwd, iv);
            var function = Factory.Create(type, key);

            return(function.Decrypt(cipherBytes, salt));
        }
Esempio n. 5
0
        public static ICryptoValue Encrypt(DesTypes type, string originalText, string pwd, string iv, string salt, Encoding encoding = null)
        {
            encoding = encoding.SafeEncodingValue();
            var key      = Factory.GenerateKey(type, pwd, iv, encoding);
            var function = Factory.Create(type, key);

            return(function.Encrypt(originalText, salt, encoding));
        }
Esempio n. 6
0
        public static ICryptoValue Decrypt(DesTypes type, string cipherText, string pwd, string iv, Encoding encoding = null)
        {
            encoding = encoding.SafeEncodingValue();
            var key      = Factory.GenerateKey(type, pwd, iv, encoding);
            var function = Factory.Create(type, key);

            return(function.Decrypt(cipherText, encoding));
        }
Esempio n. 7
0
        public static ICryptoValue Decrypt(DesTypes type, string cipherText, string pwd, string iv, string salt, CipherTextTypes cipherTextType, Encoding encoding = null, Func <string, byte[]> customConverter = null)
        {
            encoding = encoding.SafeEncodingValue();
            var key      = Factory.GenerateKey(type, pwd, iv, encoding);
            var function = Factory.Create(type, key);

            return(function.Decrypt(cipherText, salt, cipherTextType, encoding, customConverter));
        }
 public static DesKey Generate(DesTypes type, string pwd, string iv, Encoding encoding)
 {
     return(type switch
     {
         DesTypes.DES => new DesKey(DesTypes.DES, pwd, iv, encoding),
         DesTypes.TripleDES128 => new DesKey(DesTypes.TripleDES128, pwd, iv, encoding),
         DesTypes.TripleDES192 => new DesKey(DesTypes.TripleDES192, pwd, iv, encoding),
         _ => throw new ArgumentException("The length of the key is invalid.")
     });
Esempio n. 9
0
        public static IDES Create(DesTypes type, byte[] pwd, byte[] iv)
        {
            switch (type)
            {
            case DesTypes.DES:
                return(new DesFunction(GenerateKey(DesTypes.DES, pwd, iv)));

            case DesTypes.TripleDES128:
                return(new TripleDesFunction(GenerateKey(DesTypes.TripleDES128, pwd, iv)));

            case DesTypes.TripleDES192:
                return(new TripleDesFunction(GenerateKey(DesTypes.TripleDES192, pwd, iv)));

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }
Esempio n. 10
0
        public static IDES Create(DesTypes type, DesKey key)
        {
            switch (type)
            {
            case DesTypes.DES:
                return(new DesFunction(key));

            case DesTypes.TripleDES128:
                return(new TripleDesFunction(key));

            case DesTypes.TripleDES192:
                return(new TripleDesFunction(key));

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }
Esempio n. 11
0
 public static DesKey GenerateKey(DesTypes type, byte[] pwd, byte[] iv) => DesKeyGenerator.Generate(type, pwd, iv);
Esempio n. 12
0
 public static DesKey GenerateKey(DesTypes type, string pwd, string iv, Encoding encoding) => DesKeyGenerator.Generate(type, pwd, iv, encoding);
Esempio n. 13
0
 public DesKey(DesTypes type, byte[] pwd, byte[] iv)
 {
     Size = (int)type;
     Key  = CloneBytes(ref pwd);
     IV   = CloneBytes(ref iv);
 }
Esempio n. 14
0
 public static DesKey GenerateKey(DesTypes type = DesTypes.DES) => Factory.GenerateKey(type);
Esempio n. 15
0
 public static IDES Create(DesTypes type, DesKey key) => Factory.Create(type, key);
Esempio n. 16
0
 public static IDES Create(DesTypes type, byte[] pwd, byte[] iv) => Factory.Create(type, pwd, iv);
Esempio n. 17
0
 public static DesKey GenerateKey(DesTypes type, byte[] pwd, byte[] iv) => Factory.GenerateKey(type, pwd, iv);
Esempio n. 18
0
 public static IDES Create(DesTypes type) => Factory.Create(type);
Esempio n. 19
0
 public static DesKey GenerateKey(DesTypes type = DesTypes.DES) => DesKeyGenerator.Generate(type);
Esempio n. 20
0
 public static IDES Create(DesTypes type, string pwd, string iv, Encoding encoding = null) => Factory.Create(type, pwd, iv, encoding);