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."); } }
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); }
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)); }
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)); }
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)); }
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.") });
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); } }
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); } }
public static DesKey GenerateKey(DesTypes type, byte[] pwd, byte[] iv) => DesKeyGenerator.Generate(type, pwd, iv);
public static DesKey GenerateKey(DesTypes type, string pwd, string iv, Encoding encoding) => DesKeyGenerator.Generate(type, pwd, iv, encoding);
public DesKey(DesTypes type, byte[] pwd, byte[] iv) { Size = (int)type; Key = CloneBytes(ref pwd); IV = CloneBytes(ref iv); }
public static DesKey GenerateKey(DesTypes type = DesTypes.DES) => Factory.GenerateKey(type);
public static IDES Create(DesTypes type, DesKey key) => Factory.Create(type, key);
public static IDES Create(DesTypes type, byte[] pwd, byte[] iv) => Factory.Create(type, pwd, iv);
public static DesKey GenerateKey(DesTypes type, byte[] pwd, byte[] iv) => Factory.GenerateKey(type, pwd, iv);
public static IDES Create(DesTypes type) => Factory.Create(type);
public static DesKey GenerateKey(DesTypes type = DesTypes.DES) => DesKeyGenerator.Generate(type);
public static IDES Create(DesTypes type, string pwd, string iv, Encoding encoding = null) => Factory.Create(type, pwd, iv, encoding);