public static ICryptoValue Decrypt(Sm4Types type, byte[] cipherBytes, byte[] pwd) { var key = Factory.GenerateKey(pwd); var function = Factory.Create(type, key); return(function.Decrypt(cipherBytes)); }
public static ICryptoValue Encrypt(Sm4Types type, byte[] originalBytes, byte[] pwd) { var key = Factory.GenerateKey(pwd); var function = Factory.Create(type, key); return(function.Encrypt(originalBytes)); }
public static ICryptoValue Decrypt(Sm4Types type, string cipherText, string pwd, CipherTextTypes cipherTextType, Encoding encoding = null, Func <string, byte[]> customConverter = null) { encoding = encoding.SafeEncodingValue(); var key = Factory.GenerateKey(pwd, encoding); var function = Factory.Create(type, key); return(function.Decrypt(cipherText, cipherTextType, encoding, customConverter)); }
public static ICryptoValue Decrypt(Sm4Types type, string cipherText, string pwd, Encoding encoding = null) { encoding = encoding.SafeEncodingValue(); var key = Factory.GenerateKey(pwd, encoding); var function = Factory.Create(type, key); return(function.Decrypt(cipherText, encoding)); }
public static ISM4 Create(Sm4Types type = Sm4Types.ECB) { return(type switch { Sm4Types.ECB => new SM4ECBFunction(GenerateKey(type)), Sm4Types.CBC => new SM4CBCFunction(GenerateKey(type)), _ => new SM4ECBFunction(GenerateKey(type)) });
public static Sm4Key Generate(Sm4Types type, int length) { if (length <= 0) { length = 16; } var pwd = MakeBytes(length); var iv = type switch { Sm4Types.ECB => new byte[0], Sm4Types.CBC => MakeBytes(length), _ => new byte[0], }; return(new Sm4Key(pwd, iv)); }
public static Sm4Key Generate(Sm4Types type = Sm4Types.ECB) { return(Generate(type, 16)); }
public static ISM4 Create(Sm4Types type, Sm4Key key) => Factory.Create(type, key);
public static ISM4 Create(Sm4Types type, byte[] pwd, byte[] iv) => Factory.Create(type, pwd, iv);
public static ISM4 Create(Sm4Types type, string pwd, string iv, Encoding encoding = null) => Factory.Create(type, pwd, iv, encoding);
public static ISM4 Create(Sm4Types type = Sm4Types.ECB) => Factory.Create(type);
public static Sm4Key GenerateKey(Sm4Types type, int length) => Factory.GenerateKey(type, length);
public static Sm4Key GenerateKey(Sm4Types type = Sm4Types.ECB) => Factory.GenerateKey(type);
public static Sm4Key GenerateKey(Sm4Types type, int length) => Sm4KeyGenerator.Generate(type, length);
public static Sm4Key GenerateKey(Sm4Types type = Sm4Types.ECB) => Sm4KeyGenerator.Generate(type);