Esempio n. 1
0
            public static string Encrypt_ECB_Hex(string plaintext, string keyInHexFormat,
                                                 Encoding encoding = null)
            {
                if (encoding == null)
                {
                    encoding = Encoding.UTF8;
                }

                var keyBytes = Hex.Decode(keyInHexFormat);
                var sm4      = new SM4Algorithm(keyBytes, null, encoding, EncryptionResultTypes.HexString);

                return(sm4.EncryptString(plaintext, SM4Models.ECB));
            }
Esempio n. 2
0
            public static string Encrypt_ECB_Base64(string plaintext, string keyInBase64Format,
                                                    Encoding encoding = null)
            {
                if (encoding == null)
                {
                    encoding = Encoding.UTF8;
                }

                var keyBytes = Convert.FromBase64String(keyInBase64Format);
                var sm4      = new SM4Algorithm(keyBytes, null, encoding, EncryptionResultTypes.Base64String);

                return(sm4.EncryptString(plaintext, SM4Models.ECB));
            }
Esempio n. 3
0
            public static string Encrypt_CBC_Hex(string plaintext, string keyInHexFormat, string initializationVectorInHexFormat,
                                                 Encoding encoding = null)
            {
                if (encoding == null)
                {
                    encoding = Encoding.UTF8;
                }

                var keyBytes = Hex.Decode(keyInHexFormat);
                var ivBytes  = Hex.Decode(initializationVectorInHexFormat);
                var sm4      = new SM4Algorithm(keyBytes, ivBytes, encoding, EncryptionResultTypes.HexString);

                return(sm4.EncryptString(plaintext, SM4Models.CBC));
            }
Esempio n. 4
0
            public static string Encrypt_CBC_Base64(string plaintext, string keyInBase64Format, string initializationVectorInBase64Format,
                                                    Encoding encoding = null)
            {
                if (encoding == null)
                {
                    encoding = Encoding.UTF8;
                }

                var keyBytes = Convert.FromBase64String(keyInBase64Format);
                var ivBytes  = Convert.FromBase64String(initializationVectorInBase64Format);
                var sm4      = new SM4Algorithm(keyBytes, ivBytes, encoding, EncryptionResultTypes.Base64String);

                return(sm4.EncryptString(plaintext, SM4Models.CBC));
            }