我的問題是我不能使用simplexml例程加載用PHPSECLIB解密的字符串。您可以在這裏查看問題頁面 http://orwellmail.com/concrete.php無法加載字符串與從PHPSECLIB解密的simplxml
我做了一個RSA類,將PHPSECLIB中的Crypto_RSA類從http://phpseclib.sourceforge.net/環繞。我能夠解密一個字符串並將其顯示給瀏覽器。此字符串包含XML,我想用simplxml加載,但是當我加載字符串我得到這些錯誤
Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : Char 0x0 out of allowed range in /home1/dlmorris/public_html/orwellmail/concrete.php on line 37
在與原解碼我可以看到數據看起來像這樣Wireshark的時候解密的字符串是呼應到瀏覽器。我不是專家,但到處都是不合時宜的。
<.h.e.a.d.e.r.>.
.
. . .<.a.e.s._.k.e.y.>.7.W.W.q.S.Y.O.r.5.Z.i.I.w.m.V.f.D.V.c.l.K.6.m.e.G.U.V./.x.Y.e.h.G.c.l.M. J.n.L.v.C.R.U.=.<./.a.e.s._.k.e.y.>.
.
. . .<.a.e.s._.i.v.>.z.V.6.t.m.x.m.a.i.X.B.X.i.R.Q.0.b.i.n.D.t.g.=.=.<./.a.e.s._.i.v.>.
.
.<./.h.e.a.d.e.r.>.
使用mb_detect_encoding我能夠看到字符串是UTF-8。如果我對解密的字符串進行硬編碼並使用simplexml加載該字符串,它就可以工作。使用從Crypt_RSA-返回的字符串>解密包含在$ decrypted_header
我的代碼
$xml = simplexml_load_string($data);
$rsa = new RSA();
$rsa->LoadKeysFromXML($private,$public);
$decrypted_header = $rsa->DecryptString(base64_decode($xml->header));
echo $decrypted_header;
echo mb_detect_encoding($decrypted_header, 'UTF-8', TRUE); //RETURNS UTF-8
$decrypted_header_xml = simplexml_load_string($decrypted_header);
echo $decrypted_header_xml->aes_key;
XML
<header>
<aes_key>m75DRFG7uFo8usu3JrA9SUQs0QtR3hm/DmDufhc4ugI=</aes_key>
<aes_iv>xhQrKMVkN0+vWqYooY4dxg==</aes_iv>
</header>
我Crypt_RSA包裝類
相關代碼
public function DecryptString($message)
{
$this->_rsa_engine = new Crypt_RSA();
$this->_rsa_engine->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
$this->_rsa_engine->loadKey($this->_private_key,CRYPT_RSA_PRIVATE_FORMAT_XML);
return $this->_rsa_engine->decrypt($message);
}
它以UTF-16編碼。我使用iconv(「UTF-16」,「UTF-8」,$輸入)使其工作。謝謝neubert! – codenesium