PHP空白用3DES加密


PHP blank space with 3DES Encrypt

我有一个问题(服务器端),当我从客户端加密数据,我发送到web服务器与Post方法。

i使用此方法从c#客户端进行加密

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));
    }

当我发送加密字符串给PHP,如果在该字符串中有一个+,PHP读取它与一个空格。如果没有"+",那就没问题了。

例如,这是一个加密字符串4aY+na42iaPg+aep==在c#中,当我在php中读取它的4aY a42iaPg aep==所以如果我解密,如果不匹配正确的单词。

我使用这个脚本来启动read方法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 +

有办法解决吗?

是base64解码+到空格使用this:

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

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

您可以将'+'替换为其他字符(base64不使用的字符)用于发送。然后将该字符替换回'+'进行解码。