无法在我的Web服务中加密特殊字符(例如“ /”)以加密查询字符串参数

时间:2018-10-16 10:13:13

标签: asp.net ajax web-services wcf c#-4.0

我想编写一个WCF代码,其中我具有加密和解密C#中任何值的功能 并在我的JavaScript代码中使用它来加密我的查询字符串参数

代码如下:

 private string Encrypt(string clearText)
    {
        string EncryptionKey = "MAKV2SPBNI99212";
        byte[] clearBytes = Encoding.Unicode.GetBytes(clearText);
        using (Aes encryptor = Aes.Create())
        {
            Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
            encryptor.Key = pdb.GetBytes(32);
            encryptor.IV = pdb.GetBytes(16);
            using (MemoryStream ms = new MemoryStream())
            {
                using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write))
                {
                    cs.Write(clearBytes, 0, clearBytes.Length);
                    cs.Close();
                }
                clearText = Convert.ToBase64String(ms.ToArray());
            }
        }
        return clearText;
    }

我正在这样的JavaScript代码中调用此Web服务:

function Encrypt(para)
 {
  var resultEncrypt = "";
  $.ajax({  
        type: "GET",  
        url:"http://servername/site/_layouts/15/SPED/ED.svc/Call("+para+")",     
        data: "{'clearText':'clearText'}",  
        async : false,
        contentType: "application/json",  
        datatype: "json",  
        success: function(data) {  
           resultEncrypt = data.SampleServiceCallResult ;

        }  

    });
  return resultEncrypt;
}

如果我尝试对纯文本或数字进行加密。它可以正常工作。但是,如果我的字符串像“ 07/89 / HP8 / 9090”。它不起作用。

请帮助

0 个答案:

没有答案
相关问题