我正在开发一个SSO解决方案,该解决方案必须接收SAML2.0断言才能让用户登录。这一直在工作,直到断言需要加密数据。断言响应看起来是这样的(去掉了一些信息):
<samlp:Response IssueInstant="2013-07-09T21:00:22.884Z" ID="..." Version="2.0" xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol">
<saml:Issuer xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">...</saml:Issuer>
<samlp:Status>
<samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success"/>
</samlp:Status>
<saml:EncryptedAssertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">
<xenc:EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
<xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc"/>
<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<xenc:EncryptedKey xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
<xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5"/>
<xenc:CipherData>
<xenc:CipherValue>BB9KCO...gRGc7w03zZ5Q==</xenc:CipherValue>
</xenc:CipherData>
</xenc:EncryptedKey>
</ds:KeyInfo>
<xenc:CipherData>
<xenc:CipherValue>kb/HpNix...TcvxjypM</xenc:CipherValue>
</xenc:CipherData>
</xenc:EncryptedData>
</saml:EncryptedAssertion>
</samlp:Response>
正如你所看到的,有一个加密的密钥和加密的数据。他们得到了一个证书,从中提取公钥用于加密。我的理解是,我会使用我们的私钥解密EncryptedKey,然后使用该密钥解密EncryptedData。但是解密仍然失败。
我是这样测试的:
$data ='....'; //Contains the EncryptedKey cipherdata
$privateKey = '....'; //Contains the private key
$decrypted = null; //destination for decrypted data
$result = openssl_private_decrypt($data, $decrypted, $privateKey);
CCD_ 1将为FALSE并且CCD_ 2为NULL。我已经用公钥加密了数据,并用私钥成功解密了它,所以我相信包含它们的X.509证书是有效的。有人能解释一下吗?提前谢谢。
我在这里解决了这个问题。在解密之前,我需要对密钥和加密数据进行base64_decode。