コード例 #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(System.Convert.ToBase64String(output));
        }
コード例 #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  = System.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));
        }