Esempio n. 1
0
        /// <summary>
        /// 加密,与 ShoveEIMS3 的 C++ 代码兼容
        /// </summary>
        /// <param name="input"></param>
        /// <param name="key"></param>
        /// <param name="encodingName"></param>
        /// <returns></returns>
        public static string EncryptSES(string input, string key, string encodingName)
        {
            Ses ses = new Ses(key, encodingName);

            byte[] byte_input = Encoding.GetEncoding(encodingName).GetBytes(input);
            int    len        = ses.GetEncryptResultLength(byte_input);

            byte[] output = new byte[len];
            ses.Encrypt(byte_input, output);

            return(Convert.ToBase64String(output));
        }
Esempio n. 2
0
        /// <summary>
        /// 解密,与 ShoveEIMS3 的 C++ 代码兼容
        /// </summary>
        /// <param name="input"></param>
        /// <param name="key"></param>
        /// <param name="encodingName"></param>
        /// <returns></returns>
        public static string DecryptSES(string input, string key, string encodingName)
        {
            if (String.IsNullOrEmpty(input))
            {
                return("");
            }

            Ses ses = new Ses(key, encodingName);

            byte[] byte_input  = Convert.FromBase64String(input);
            byte[] temp_output = new byte[input.Length];

            int output_len = 0;

            ses.Decrypt(byte_input, byte_input.Length, temp_output, ref output_len);

            byte[] ouput = new byte[output_len];
            Array.Copy(temp_output, ouput, output_len);

            return(Encoding.GetEncoding(encodingName).GetString(ouput));
        }