PHPMike
PHPMike

Reputation: 1

How can I generate the CipherValue of an EncryptedKey with rsa-oaep-mgf1p encryption method and sha1 digest method?

Anyone know how can I generate the CipherValue of the EncryptedKey? This example was generated with VB.Net

I suppose there is something like encrypt a token with the public key and a SHA1 of this token but I have no idea how it combined. I want to do that in PHP but I haven't found any tool.

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

Upvotes: 0

Views: 1019

Answers (1)

neubert
neubert

Reputation: 16782

The XML says it's doing RSA OAEP and that it's using sha1. So, my guess, is that this would work, provided you have the public key:

(using phpseclib)

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

(phpseclib 2.0 uses OAEP by default and sha1 as the MGF / hash)

Upvotes: 0

Related Questions