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条)

报告相同问题?