Exemplo n.º 1
0
        /// <summary>
        /// sm4加密
        /// </summary>
        /// <param name="value">原始字段</param>
        /// <returns>加密数据</returns>
        public static string SM4Encrypt(string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                return("");
            }
            var ciphertext = SM4EncryptHelper.is_sm4_ciphertext(value, value.Length);

            if (ciphertext == (int)SM4_ERROR_CODE.SM4_SUCCESS)
            {
                return(value);
            }
            int    outlen = 0;
            IntPtr ip     = IntPtr.Zero;
            var    iflg   = SM4EncryptHelper.sm4_encrypt(value, value.Length, out ip, out outlen);

            string result = "";

            if (iflg == (int)SM4_ERROR_CODE.SM4_SUCCESS)
            {
                byte[] array = new byte[outlen];
                Marshal.Copy(ip, array, 0, outlen);
                result = Encoding.UTF8.GetString(array);
            }
            SM4EncryptHelper.sm4_freebuf(out ip);
            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// sm4加密
        /// </summary>
        /// <param name="value">原始字段</param>
        /// <returns>加密数据</returns>
        public static string SM4Encrypt(string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                return("");
            }
            int    outlen = 0;
            IntPtr ip     = IntPtr.Zero;
            var    iflg   = SM4EncryptHelper.sm4_encrypt(value, value.Length, out ip, out outlen);

            byte[] array = new byte[outlen];
            Marshal.Copy(ip, array, 0, outlen);

            var result = Encoding.UTF8.GetString(array);

            SM4EncryptHelper.sm4_freebuf(out ip);
            return(result);
        }