我有一个需要解密的加密 SAML 2.0 响应/断言。格式如下:
<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、passport-saml 导入私钥文件并尝试解密响应时,如果我省略 ("-----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.
})
任何解决方法将不胜感激。
我想我想通了。对于那些正在为类似问题而苦苦挣扎的人,您必须包含---BEGIN RSA PRIVATE KEY---
和---END RSA PRIVATE KEY---
。如果不包含横幅,则passport-saml lib 所依赖的node-forge 库将引发错误。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句