donglaogu3788 2011-11-19 20:07
浏览 51
已采纳

带有3DES加密的PHP空白区域

I have a problem (server side) when i encrypt data from a client and i send to webserver with Post Method.

i Use this Method to Encrypt from a C# Client

public string Encrypt3DES(string strString)
    {
        DESCryptoServiceProvider DES = new DESCryptoServiceProvider();

        DES.Key = Encoding.GetBytes(this.Key);
        DES.Mode = CipherMode.ECB;
        DES.Padding = PaddingMode.Zeros;

        ICryptoTransform DESEncrypt = DES.CreateEncryptor();

        byte[] Buffer = encoding.GetBytes(strString);

        return Convert.ToBase64String(DESEncrypt.TransformFinalBlock(Buffer, 0, Buffer.Length));
    }

When i send ecrypted String to PHP if there was a + in that string, php read it with a blank space. If instead there'isnt any '+' i haven't any problem.

For Example this is a Encrypted String 4aY+na42iaPg+aep== in C# when i read in php it's 4aY a42iaPg aep== so if i decrypt if dont match with the correct word.

i use this script to start read method post

   if (isset($_POST['doConvalid'])){    
if ($_POST['doConvalid']=='Convalid')
{
    foreach($_POST as $keys => $values) {
    $data[$keys] =($values); // post variables are filtered
}

$cheking=$data['check'];
echo("Show checking = $checking"); //Here i read string with blank space instead +

Is there a way to fix it?

  • 写回答

2条回答 默认 最新

  • dongyuedaochen8415 2011-11-19 20:22
    关注

    Yes base64 decodes + to space use this:

    echo str_replace(" ","+",$_POST['string']);
    

    http://en.wikipedia.org/wiki/Base64#URL_applications

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题