Ejemplo n.º 1
0
        public static ICryptoValue Decrypt(AesTypes 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));
        }
Ejemplo n.º 2
0
        public static ICryptoValue Encrypt(AesTypes 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 AesKey Generate(AesTypes type)
        {
            switch (type)
            {
            case AesTypes.Aes128:
            {
                using var provider = new AesCryptoServiceProvider { KeySize = (int)type };
                return(new AesKey(AesTypes.Aes128, provider.Key, provider.IV));
            }

            case AesTypes.Aes192:
            {
                using var provider = new AesCryptoServiceProvider { KeySize = (int)type };
                return(new AesKey(AesTypes.Aes192, provider.Key, provider.IV));
            }

            case AesTypes.Aes256:
            {
                using var provider = new AesCryptoServiceProvider { KeySize = (int)type };
                return(new AesKey(AesTypes.Aes256, provider.Key, provider.IV));
            }

            default:
                throw new ArgumentException("The length of the key is invalid.");
            }
        }
Ejemplo n.º 4
0
 public AesKey(AesTypes type, string pwd, string iv, Encoding encoding = null)
 {
     encoding = encoding.SafeEncodingValue();
     Size     = (int)type;
     Key      = encoding.SafeEncodingValue().GetBytes(pwd);
     IV       = encoding.SafeEncodingValue().GetBytes(iv);
 }
Ejemplo n.º 5
0
        public static ICryptoValue Decrypt(AesTypes 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));
        }
Ejemplo n.º 6
0
        public static ICryptoValue Encrypt(AesTypes 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));
        }
Ejemplo n.º 7
0
        public static ICryptoValue Decrypt(AesTypes 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 AesKey Generate(AesTypes type, string pwd, string iv, Encoding encoding)
 {
     return(type switch
     {
         AesTypes.Aes128 => new AesKey(AesTypes.Aes128, pwd, iv, encoding),
         AesTypes.Aes192 => new AesKey(AesTypes.Aes192, pwd, iv, encoding),
         AesTypes.Aes256 => new AesKey(AesTypes.Aes256, pwd, iv, encoding),
         _ => throw new ArgumentException("The length of the key is invalid.")
     });
Ejemplo n.º 9
0
 public static IAES Create(AesTypes type) => Factory.Create(type);
Ejemplo n.º 10
0
 public static IAES Create(AesTypes type, byte[] pwd, byte[] iv) => new AesFunction(GenerateKey(type, pwd, iv));
Ejemplo n.º 11
0
 public static IAES Create(AesTypes type, string pwd, string iv, Encoding encoding = null) => new AesFunction(GenerateKey(type, pwd, iv, encoding));
Ejemplo n.º 12
0
 public static IAES Create(AesTypes type, AesKey key) => Factory.Create(type, key);
Ejemplo n.º 13
0
 public static IAES Create(AesTypes type, AesKey key) => new AesFunction(key);
Ejemplo n.º 14
0
 public static IAES Create(AesTypes type, string pwd, string iv, Encoding encoding = null) => Factory.Create(type, pwd, iv, encoding);
Ejemplo n.º 15
0
 public static IAES Create(AesTypes type, byte[] pwd, byte[] iv) => Factory.Create(type, pwd, iv);
Ejemplo n.º 16
0
 public static AesKey GenerateKey(AesTypes type = AesTypes.Aes256) => AesKeyGenerator.Generate(type);
Ejemplo n.º 17
0
 public static IAES Create(AesTypes type) => new AesFunction(GenerateKey(type));
Ejemplo n.º 18
0
 public static AesKey GenerateKey(AesTypes type = AesTypes.Aes256) => Factory.GenerateKey(type);
Ejemplo n.º 19
0
 public static AesKey GenerateKey(AesTypes type, byte[] pwd, byte[] iv) => Factory.GenerateKey(type, pwd, iv);
Ejemplo n.º 20
0
 public static AesKey GenerateKey(AesTypes type, string pwd, string iv, Encoding encoding) => Factory.GenerateKey(type, pwd, iv, encoding);
Ejemplo n.º 21
0
 public AesKey(AesTypes type, byte[] pwd, byte[] iv)
 {
     Size = (int)type;
     Key  = CloneBytes(ref pwd);
     IV   = CloneBytes(ref iv);
 }
Ejemplo n.º 22
0
 public static AesKey GenerateKey(AesTypes type, byte[] pwd, byte[] iv) => AesKeyGenerator.Generate(type, pwd, iv);