1
我有一個加密的SAML 2.0響應/聲明,我需要解密。格式如下:passport-saml lib沒有正確解密saml使用私鑰解密密鑰的加密聲明
<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>
<xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"/>
<xenc:CipherData>
<xenc:CipherValue>{some ciphers}</xenc:CipherValue>
</xenc:CipherData>
</xenc:EncryptedKey>
</ds:KeyInfo>
<xenc:CipherData>
<xenc:CipherValue>{assertion body}</xenc:CipherValue>
</xenc:CipherData>
</xenc:EncryptedData>
</saml:EncryptedAssertion>
我也有格式像這樣的私人解密密鑰:
-----BEGIN RSA PRIVATE KEY-----
{mumbo jumbos}
-----END RSA PRIVATE KEY-----
我一直在使用OneLogin的SAML解密工具,這裏解密加密SAML斷言(複印件試圖+粘貼到該輸入框),它就像一個魅力。 https://www.samltool.com/decrypt.php
然而,當我試圖用的NodeJS,護照SAML導入私鑰文件,並嘗試解密響應,它得到了「格式化無效PEM」如果我忽略(「----- BEGIN ----「或」--- END ---「標題),否則會出現」無效的RSAES-OAEP填充「錯誤。
這是我的代碼片段:
const fs = require('fs');
const Promise = require('bluebird');
const path = require('path');
const forge = require('node-forge');
let pkey = fs.readFileSync(path.join(__dirname,'./myTestKey.pem'), 'utf8');
//let testKey = new Buffer(pkey).toString('base64');
let SAML = require('passport-saml/lib/passport-saml/saml.js');
let saml = new SAML({...,decryptionPvk: pkey });
let validatePostResponseAsync = Promise.promisify(saml.validatePostResponse);
validatePostResponseAsync(myResponse, pkey)
.then(response=>{
})
.catch(error=>{
// it always throw error of the 2 mentioned above.
})
任何解決辦法,將不勝感激。
@dlongley如果我的私鑰是ASCII/UTF8格式純字符串,會發生什麼情況 – WABBIT0111