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)); }
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."); } }
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); }
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)); }
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)); }
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.") });
public static IAES Create(AesTypes type) => Factory.Create(type);
public static IAES Create(AesTypes type, byte[] pwd, byte[] iv) => new AesFunction(GenerateKey(type, pwd, iv));
public static IAES Create(AesTypes type, string pwd, string iv, Encoding encoding = null) => new AesFunction(GenerateKey(type, pwd, iv, encoding));
public static IAES Create(AesTypes type, AesKey key) => Factory.Create(type, key);
public static IAES Create(AesTypes type, AesKey key) => new AesFunction(key);
public static IAES Create(AesTypes type, string pwd, string iv, Encoding encoding = null) => Factory.Create(type, pwd, iv, encoding);
public static IAES Create(AesTypes type, byte[] pwd, byte[] iv) => Factory.Create(type, pwd, iv);
public static AesKey GenerateKey(AesTypes type = AesTypes.Aes256) => AesKeyGenerator.Generate(type);
public static IAES Create(AesTypes type) => new AesFunction(GenerateKey(type));
public static AesKey GenerateKey(AesTypes type = AesTypes.Aes256) => Factory.GenerateKey(type);
public static AesKey GenerateKey(AesTypes type, byte[] pwd, byte[] iv) => Factory.GenerateKey(type, pwd, iv);
public static AesKey GenerateKey(AesTypes type, string pwd, string iv, Encoding encoding) => Factory.GenerateKey(type, pwd, iv, encoding);
public AesKey(AesTypes type, byte[] pwd, byte[] iv) { Size = (int)type; Key = CloneBytes(ref pwd); IV = CloneBytes(ref iv); }
public static AesKey GenerateKey(AesTypes type, byte[] pwd, byte[] iv) => AesKeyGenerator.Generate(type, pwd, iv);