2013-07-11 15 views
0

我正在開發SSO解決方案,該解決方案必須接收用戶所在日誌的SAML2.0斷言。直到斷言需要加密數據爲止。斷言響應如下所示(有些信息被刪除):PingIdentity SAML2.0 EncryptedAssertion - 加密數據解密失敗

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

$result將是FALSE和$decrypted爲NULL。我用公鑰加密了數據,並用私鑰解密了數據,所以我相信包含它們的X.509證書是有效的。有人可以對此有所瞭解嗎?提前致謝。

回答

0

我在這裏找到了問題。在解密之前,我需要對cipherkey和cipherdata進行base64_decode。