Ejemplo n.º 1
0
        /// <summary>
        /// 加密串
        /// </summary>
        /// <param name="buffer">密钥</param>
        /// <param name="len">长度=8</param>
        /// <param name="key">传入的明码密码</param>
        /// <returns></returns>
        public static string EncodeString(string buffer, int len, string key)
        {
            try
            {
                if (buffer == null)
                {
                    throw new ArgumentNullException("buffer", "传入密钥为空");
                }
                if (string.IsNullOrEmpty(key))
                {
                    key = string.Empty;
                }

                char[] pbuffer = new char[1024];
                char[] pkey    = new char[80];

                HisEncryption encryption = new HisEncryption();
                buffer.ToCharArray().CopyTo(pbuffer, 0);
                key.ToCharArray().CopyTo(pkey, 0);
                encryption.Secret(pbuffer, len, pkey);
                byte[] encryptBytes = CharArray2ByteArray(len, encryption);
                return(Convert.ToBase64String(encryptBytes));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 加密字符串sql用,形式为Char(xx)+Char(xx)...
        /// </summary>
        /// <param name="buffer">密钥</param>
        /// <param name="len">长度=8</param>
        /// <param name="key">传入的明码密码</param>
        /// <returns></returns>
        public static string EncodeStringSql(string buffer, int len, string key)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer", "传入密钥为空");
            }
            if (string.IsNullOrEmpty(key))
            {
                key = string.Empty;
            }

            char[] pbuffer = new char[1024];
            char[] pkey    = new char[80];
            string s       = "";

            char[] ckey;

            HisEncryption encryption = new HisEncryption();

            buffer.ToCharArray().CopyTo(pbuffer, 0);
            key.ToCharArray().CopyTo(pkey, 0);
            encryption.Secret(pbuffer, len, pkey);
            ckey = encryption.EncryptPassword.ToCharArray();
            s    = "char(" + Convert.ToByte(ckey[0]).ToString() + ")";
            for (int i = 1; i < len; i++)
            {
                s = s + "+char(" + Convert.ToByte(ckey[i]).ToString() + ")";
            }
            s = s + "+char(0)";
            return(s);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 加密串
        /// </summary>
        /// <param name="buffer">密钥</param>
        /// <param name="len">长度=8</param>
        /// <param name="key">传入的明码密码</param>
        /// <returns>返回字符数组</returns>
        public static byte[] EncodeString2ByteArray(string buffer, int len, string key)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer", "传入密钥为空");
            }
            if (string.IsNullOrEmpty(key))
            {
                key = string.Empty;
            }

            char[] pbuffer = new char[1024];
            char[] pkey    = new char[80];

            HisEncryption encryption = new HisEncryption();

            buffer.ToCharArray().CopyTo(pbuffer, 0);
            key.ToCharArray().CopyTo(pkey, 0);
            encryption.Secret(pbuffer, len, pkey);

            return(CharArray2ByteArray(len, encryption));
        }