PHP escapeshellarg()不';行不通

PHP escapeshellarg()不';行不通,php,encryption,Php,Encryption,在第一个shell\u exec()上,我加密了一条消息,在第二个shell\u exec()上,我想解密我的密码。加密和解密函数运行良好。第一个shell\u exec()返回的数据类型在第二个shell\u exec()中不能用作变量。我能做什么 <?php $plaintext = "unpuzzle"; echo '<p>'.$plaintext.'</p>'; $criptotext = shell_exec('java DES '. escapes

在第一个
shell\u exec()
上,我加密了一条消息,在第二个
shell\u exec()
上,我想解密我的密码。加密和解密函数运行良好。第一个
shell\u exec()
返回的数据类型在第二个
shell\u exec()
中不能用作变量。我能做什么

<?php
 $plaintext = "unpuzzle";
 echo '<p>'.$plaintext.'</p>';
 $criptotext = shell_exec('java DES '. escapeshellarg($plaintext) .' 1');
 echo '<p>Criptotext: ' . $criptotext . '</p>';
 $plaintext = shell_exec('java DES '. escapeshellarg($criptotext) .' 2');
 echo '<p>Plaintext: ' . $plaintext . '</p>';
?>

shell_exec
返回命令的输出,其中包括结尾的换行符。在将其用作加密文本之前,需要删除换行符

$criptotext = rtrim(shell_exec('java DES ' . escapeshellarg($plaintext) . ' 1'), "\r\n");

var_dump($criptotext)
显示了什么?string(17)“4DC4B9F5CF6ACF46”似乎我的密码后面有一个空格字符,因为解密函数无法工作……我使用trim()解决了这个问题,感谢您的观察!你知道为什么我会得到那个空格字符,因为它不是来自我的java类。我在答案中解释了它。这是一条新线,不是空间。