コード例 #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));
        }
コード例 #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));
        }
コード例 #3
0
        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.");
            }
        }
コード例 #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);
 }
コード例 #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));
        }
コード例 #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));
        }
コード例 #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));
        }
コード例 #8
0
 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.")
     });
コード例 #9
0
 public static IAES Create(AesTypes type) => Factory.Create(type);
コード例 #10
0
 public static IAES Create(AesTypes type, byte[] pwd, byte[] iv) => new AesFunction(GenerateKey(type, pwd, iv));
コード例 #11
0
 public static IAES Create(AesTypes type, string pwd, string iv, Encoding encoding = null) => new AesFunction(GenerateKey(type, pwd, iv, encoding));
コード例 #12
0
 public static IAES Create(AesTypes type, AesKey key) => Factory.Create(type, key);
コード例 #13
0
 public static IAES Create(AesTypes type, AesKey key) => new AesFunction(key);
コード例 #14
0
 public static IAES Create(AesTypes type, string pwd, string iv, Encoding encoding = null) => Factory.Create(type, pwd, iv, encoding);
コード例 #15
0
 public static IAES Create(AesTypes type, byte[] pwd, byte[] iv) => Factory.Create(type, pwd, iv);
コード例 #16
0
 public static AesKey GenerateKey(AesTypes type = AesTypes.Aes256) => AesKeyGenerator.Generate(type);
コード例 #17
0
 public static IAES Create(AesTypes type) => new AesFunction(GenerateKey(type));
コード例 #18
0
 public static AesKey GenerateKey(AesTypes type = AesTypes.Aes256) => Factory.GenerateKey(type);
コード例 #19
0
 public static AesKey GenerateKey(AesTypes type, byte[] pwd, byte[] iv) => Factory.GenerateKey(type, pwd, iv);
コード例 #20
0
 public static AesKey GenerateKey(AesTypes type, string pwd, string iv, Encoding encoding) => Factory.GenerateKey(type, pwd, iv, encoding);
コード例 #21
0
 public AesKey(AesTypes type, byte[] pwd, byte[] iv)
 {
     Size = (int)type;
     Key  = CloneBytes(ref pwd);
     IV   = CloneBytes(ref iv);
 }
コード例 #22
0
 public static AesKey GenerateKey(AesTypes type, byte[] pwd, byte[] iv) => AesKeyGenerator.Generate(type, pwd, iv);