示例#1
0
        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));
        }
示例#2
0
        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));
        }
示例#3
0
        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));
        }
示例#4
0
        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))
     });
示例#6
0
        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));
        }
示例#7
0
 public static Sm4Key Generate(Sm4Types type = Sm4Types.ECB)
 {
     return(Generate(type, 16));
 }
示例#8
0
 public static ISM4 Create(Sm4Types type, Sm4Key key) => Factory.Create(type, key);
示例#9
0
 public static ISM4 Create(Sm4Types type, byte[] pwd, byte[] iv) => Factory.Create(type, pwd, iv);
示例#10
0
 public static ISM4 Create(Sm4Types type, string pwd, string iv, Encoding encoding = null) => Factory.Create(type, pwd, iv, encoding);
示例#11
0
 public static ISM4 Create(Sm4Types type = Sm4Types.ECB) => Factory.Create(type);
示例#12
0
 public static Sm4Key GenerateKey(Sm4Types type, int length) => Factory.GenerateKey(type, length);
示例#13
0
 public static Sm4Key GenerateKey(Sm4Types type = Sm4Types.ECB) => Factory.GenerateKey(type);
示例#14
0
 public static Sm4Key GenerateKey(Sm4Types type, int length) => Sm4KeyGenerator.Generate(type, length);
示例#15
0
 public static Sm4Key GenerateKey(Sm4Types type = Sm4Types.ECB) => Sm4KeyGenerator.Generate(type);