dekked Posted February 28, 2012 Report Share Posted February 28, 2012 Bom dia, Tenho em mãos um projecto que envolve a criação de um sistema com seamless logon, que através de um request, abre uma sessão de utilizador no software em questão. Estou a começar com as regras de encriptação. No manual que me foi fornecido, tenho isto: _____________________________________________________ Appendix E: Encryption and hashing example This section deals with the values of the data at various stages during the encryption and generation of the digital signature. Using the following Seamless Logon account details: Shared key 8D2F1D29A48F01F16B53EF8BB629E0B5BD312F7C13F62BF4C41299D5857124D0 IV 8D2F1D29A48F01F16B53EF8BB629E0B5 Company ID 999 User ID test Product ID 3 Host address 195.102.120.10 Destination address 53.218.121.84 The first step is to create the XML content for the Body element, see below: <Resource name="Session"> <HostAddress>195.102.120.10</HostAddress> <DestinationAddress>53.218.121.84</DestinationAddress> <CustomerID>999</CustomerID> <ProductID>3</ProductID> <AccessLevel /><MID /><Category /> <UserID>test</UserID> </Resource> This XML should then be encrypted using the shared key and the Rijndael algorithm with: a block size of 128 bits, Encryption Mode of CBC (Cypher Block Chaining) the padding mode set to zeros, i.e. pad with bytes whose value is zero, i.e. null, to make the body a multiple of the block size. The result must be converted to a hexadecimal string, see below: B0436CBFBC5CAAFB7339AF4A1DF845974D53B9D369146E2E4F1451929D9EBE25436 3E983F4F94517EB9585FDB112E7B1CCE11A33C5BBA23F8D5DE9D3415BA526489AC7 96A36FBA76D4293C8DFB673708CED10C9732EEC472D9E43D2626AA104121666E79D D8F2FF6BAC0143BD62E0EE826AF6459779C162613508D48BFE2FC8DD558A1834D72 05F96EA8D446E9B371E78E990A3995B1052DCBA9CA0AF99CC77ED2A8B55B2B882BA 29D4BB4B07FA91AB4D2F10FBB93732B077335A7E6D96FE813AEDC3711A85CD0C13A E22B28C14FCCE3AF4C1F5D2C0F7697DEC7487CCFC0ED4E77B1B65F39BAD5236E3D3 C69D33FC484 This hexadecimal string becomes the content of the Body element in the XML that is posted to the web service. ___________________________________________________________ Ando às voltas com algum código php que encontrei, mas como nunca trabalhei a este nível, estou um bocado perdido.. Podem-me dar algumas dicas para fazer isto? Obrigado e cumprimentos Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted February 28, 2012 Report Share Posted February 28, 2012 ve isto e diz o que não percebes http://www.php.net/manual/en/function.mcrypt-encrypt.php IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
dekked Posted February 28, 2012 Author Report Share Posted February 28, 2012 <?php $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC); $iv = "8D2F1D29A48F01F16B53EF8BB629E0B5"; $key = "8D2F1D29A48F01F16B53EF8BB629E0B5BD312F7C13F62BF4C41299D5857124D0"; $text = "<Resource name=\"Session\"><HostAddress>195.102.120.10</HostAddress><DestinationAddress>53.218.121.84</DestinationAddress><CustomerID>999</CustomerID><ProductID>3</ProductID><AccessLevel /><MID /><Category/><UserID>test</UserID></Resource>"; echo strlen($text) . "\n"; $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $text, MCRYPT_MODE_CBC, $iv); echo strlen($crypttext) . "\n"; ?> Quando executo, surgem os seguintes erros: Warning: mcrypt_encrypt() [function.mcrypt-encrypt]: Size of key is too large for this algorithm in C:\xampp\htdocs\SEAMLESS\enc.php on line 21 Warning: mcrypt_encrypt() [function.mcrypt-encrypt]: The IV parameter must be as long as the blocksize in C:\xampp\htdocs\SEAMLESS\enc.php on line 21 Sendo estes valores hexadecimais, posso trata-los como strings? Cumprimentos Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted February 28, 2012 Report Share Posted February 28, 2012 corri este código no meu servidor e deu sem problemas $iv = "8D2F1D29A48F01F16B53EF8BB629E0B5"; $key = "8D2F1D29A48F01F16B53EF8BB629E0B5BD312F7C13F62BF4C41299D5857124D0"; $text = "<Resource name=\"Session\"><HostAddress>195.102.120.10</HostAddress><DestinationAddress>53.218.121.84</DestinationAddress><CustomerID>999</CustomerID><ProductID>3</ProductID><AccessLevel /><MID /><Category/><UserID>test</UserID></Resource>"; $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $text, MCRYPT_MODE_CBC, $iv); $hex = ""; for ($i=0; $i < strlen($crypttext); $i++) { $hex .= dechex(ord($crypttext[$i])); } echo $hex . "\n"; IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
dekked Posted February 28, 2012 Author Report Share Posted February 28, 2012 Estranho, no meu da-me o seguinte: Warning: mcrypt_encrypt() [function.mcrypt-encrypt]: Size of key is too large for this algorithm in C:\xampp\htdocs\SEAMLESS\enc.php on line 6 Warning: mcrypt_encrypt() [function.mcrypt-encrypt]: The IV parameter must be as long as the blocksize in C:\xampp\htdocs\SEAMLESS\enc.php on line 6 c0196bd5f29e8b885cabb4d9dd83982a97690a7c56935d0c4a0d0ed11d9bccc4117b4cd2125b3d6b5dca6d078fab7c4f786c96d6ae7154ab84a858c34d9e435549fa9d462e9856a79a6535f9cf427683418e61ac3d59254d48171ec8bf3f89bafcf17f69a35021fae571686f13575ccc0b321e7c880ea29c2bbffa0a39fbf3f4702d9de0f6ee5f25ccbb5e7cb51307735751bb787b34b608d2f4b64d3bfd79439e2d034ffd16b9e3c9ab7fc65810c9c38942c374810c7b7593798afdbbc85c718cc75133c7b34de58dd1dbffd2ac0c0b9115da5f373a56cf4ccdd1897574e8e12af1ef3062a2c5dd apesar de indicar o resultado da encriptação, indica 2 erros. Link to comment Share on other sites More sharing options...
dekked Posted March 2, 2012 Author Report Share Posted March 2, 2012 Entretanto já consegui resolver o problema. Após fazer o request, recebo de volta o seguinte XML, do qual preciso de extrair o que está entre as tags <body>, e transformar numa variável. Como faço isso? <Payload> <Header> <Signature> A50E59C1BCEEC0DB3268CCA4ADF39FC782EB5B98FDF23 </Signature> <PlainTextLength> 313 </PlainTextLength> </Header> <Body>DAAA11B1970FBE20F80C40AFCAEF83403D998B3702847F1A64BB2CB74E2F853A63B6D1EEDF709ECF5325FC54159C7ACA42843A4276943350E09B266FFA84725099352CF6EB47BB579C285E36C41858991868D00CD950C93CBF9EB154F1E7F612AEA9D7172568C2155671F7E7201BC873B6CD86B0C374786E1D0BA80F6152DD4E8CC88DBE65713B5 </Body> </Payload> Cumprimentos Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted March 2, 2012 Report Share Posted March 2, 2012 http://pt2.php.net/manual/en/simplexml.examples-basic.php $payload = new SimpleXMLElement($string); echo $payload->Body; IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now