首页 > 解决方案 > 如何使用 rsa-oaep-mgf1p 加密方法和 sha1 摘要方法生成 EncryptedKey 的 CipherValue?

问题描述

任何人都知道如何生成 EncryptedKey 的 CipherValue?这个例子是用 VB.Net 生成的

我想有类似用公钥和这个令牌的 SHA1 加密令牌的东西,但我不知道它是如何组合的。我想在 PHP 中做到这一点,但我还没有找到任何工具。

<e:EncryptedKey xmlns:e="http://www.w3.org/2001/04/xmlenc#" Id="uuid-7dcc6d1e-6d3b-4ac3-a013-a75550f3e9f7-1">
    <e:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"><DigestMethod xmlns="http://www.w3.org/2000/09/xmldsig#" Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /></e:EncryptionMethod>
    <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
        <o:SecurityTokenReference>
           <o:KeyIdentifier ValueType="http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1#ThumbprintSHA1" EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">UE8lna0CUXfunLavERh30l1lQjQ=</o:KeyIdentifier>
        </o:SecurityTokenReference>
    </KeyInfo>
    <e:CipherData>
        <e:CipherValue>k9UiWxqVrQqj4674bFDcPSW6waF8wGLKwvARONEMjATyX7RZty2z9N154ycO8PXmSDTMSvBDdyC6ZMAXa3d1WH3+P9IGN9FKPsAi7oOnVGab6ikXt2bQaljxlGvaAAbiVS+BiY5x15jhzrXCCIIrEq4rsrQm9oiMFV1D1s7kPguE/TRNkT8XzOMArJ7Sk2DZVs7A4LF8dcKDH+W2Ece5JmD/H9spOQWPBRcyH29nbVy8l3/F2oTphV1UMy8Bwuax66majDmL1CqlZ5n5t9wbTuRm4rG6MLwcdZi+1xj8V0LDqs/HpxDtyHNAXcnogIu7+BBN6Rw5xX7GfZsXF0tp+w==</e:CipherValue>
    </e:CipherData>
    <e:ReferenceList>
       <e:DataReference URI="#_2" />
    </e:ReferenceList>
</e:EncryptedKey>

标签: phpsoapwsse

解决方案


XML 说它正在执行 RSA OAEP 并且它正在使用 sha1。所以,我的猜测是,如果你有公钥,这会起作用:

(使用 phpseclib)

$rsa = new RSA();
$rsa->loadKey('...');
$rsa->encrypt('...');

(phpseclib 2.0 默认使用 OAEP 和 sha1 作为 MGF/hash)


推荐阅读