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