/** * @Test * @return void */ public function testUnsealFromJava() { $privateKey = <<<EOD -----BEGIN RSA PRIVATE KEY----- MIICXgIBAAKBgQCr6s9ae6uMrAdXUNpxRcBfHUMp61jkIMbRcirjn6W02JVaoyyl AA7LHSqs1iIrSsK0bCaWONajmKqFfFXEb2NrSywXEyzPHeFEYE2wHHHcvbKkIyF6 hi2lXTTPvtxw1GUTae089XJnwLlbZ9uoMpIB7sG9TGRpuDDNE6CG2kxmCwIDAQAB AoGAfbz+rYI4RWno8J7tNd27RpXDctx0Jl4mrDehUNyKOQwTqLghxgiVyU7q0IDJ evpyD73uNv8ZVYwqY/k9Ta/eeP5wlv1o82ITFkrEsSvMy55R0KnABffEo4Lbpv5i G+5jiFq5Bo570ggk+4WtNvD21JHUVX0SEZaMPqpym7sOeTkCQQDgTxJqlyRkYWhT CWVo5O/ouxqmN+x5g16ZLM7FokISmn925mDRv7wzDR318tRhbO0VIDQA4ZT+FcGI LnLYhti1AkEAxDTOypWb98afgQthdLHnCrg7mEkZBfLS/wT3NzpaFC0D7wDOrC9i rbTvxTYOp82TOyNmthFG5ihIpRyq1SM7vwJBAKOMA7mEChzGiPJCX5ZjlijygzO+ gsT2a/rzGLAw5kv6KgXfY6iLTAVNAxNYwlFmwlYs7L3XvHKmGj3Y4BPP/iECQQC0 r7D0LRzJ7Fc9Xn6sGZ0caRcwobhymvEmOqtzZ8BGrkHeGw840BZ+w46/PY33iECb CHnxFy4EjHqB20mTKHQ/AkEAsgxTePttK36TdiX8QuS8/cxZ47tQp5QzxGCP4VpA +mK4mmUsA22Y24xbGGPy6ekgUQSxL46zil2m+QHV2w0sMg== -----END RSA PRIVATE KEY----- EOD; $sealed = 'HOQnoFwOjZoU@QeR2pU68ShpGDoipKCPWWlu28ih8vjUkI4oftMD6qgP9sa0KN8QTlcw1QLWpbvnkZIKxJ5wu12AXtgv6EdIjuvS+GNT4BcWGZz7cadTwtB5JADO8FZMKcEsShO9v1gjrJaobUZxBp5Y0roJJt0zG+feUsAlzHzswVfJ+ieEavTo='; $opened = Ulink_CryptoUtils::unseal($sealed, $privateKey); $this->assertEquals("foobarbaz", $opened); }
/** * @throws Exception\UlinkException * @param string $rawData * @return array */ public function decrypt($rawData) { $packet = Ulink_TransportPacket::createFromJson($rawData); if (!$packet) { throw new UlinkException('Can not decrypt packet!'); } if ($this->getClientId() != $packet->getClientId()) { throw new UlinkException('Client id does not match the id given in configuration!'); } if (!$packet->getSignature()) { throw new UlinkException('Packet signature is broken!'); } if (!$packet->validateAgainstKey($this->getPublicKeyPem())) { throw new UlinkException('Data signature does not match the packet content!'); } $responseJson = Ulink_CryptoUtils::unseal($packet->getRequest(), $this->getPrivateKeyPem()); $response = Ulink_RequestFactory::createFromJson($responseJson); $result = array('clientTransactionId' => $response->getClientTransactionId(), 'amount' => (string) $response->getAmount(), 'currency' => $response->getCurrency()); $goBackUrl = $response->getGoBackUrl(); if ($goBackUrl) { $result['goBackUrl'] = $goBackUrl; } $responseUrl = $response->getResponseUrl(); if ($responseUrl) { $result['responseUrl'] = $responseUrl; } if (Ulink_PaymentResponse::clazz() == get_class($response)) { $result = array_merge($result, array('timestamp' => $response->getTimestamp(), 'success' => $response->isSuccess(), 'errors' => $response->getErrors(), 'errorCodes' => $response->getErrorCodes(), 'isTest' => $response->isTest())); } $order = $response->getOrder(); if ($order && count($order->getItems())) { $items = $order->getItems(); $result['order'] = array(); foreach ($items as $item) { $result['order'][] = array('name' => $item->getName(), 'description' => $item->getDescription(), 'oneItemPrice' => (string) $item->getOneItemPrice(), 'quantity' => $item->getQuantity()); } } return $result; }
public function testPaymentIn() { $privKey = $this->getPrivateKeyPem(); $pubKey = $this->getPublicKeyPem(); $rawData = 'ulink:0.9:15:XKXvKJpR1iZZiTyYfctuDbnnIAj8WDaCtS9EbYlZxTKdUM9fbfdWWrcg7Lt7k5EuWxP8ai3q1lLe8tNeXKNaTURmFHjWs0WFObssqjKPW0LOxtqEfFPmZ88M1IkjrlYGV1UDKq/vbbdN2d2VVjv1poQr3aW9sXq4UKgUcVsM1irA0bswreyo32UMat62UVQa/jO1ktpc0cxv5CEny75zY0s1RS+9s8orFX6uQPRJOpFRQ2vRlUWjrnwdhdQrBtqzInml09Cs9MiZEaLcHTCrLUBIVJ4h@SgiRRv+oOinM3vA9aDOsfTGjzLePXWRD/ahmryLYEMpK84F4lV2uZAJflxjFDI6+sjX1DGq0vNDE0RUOLw5aSw==:onccukVgVf1T+cyA2CfExPdRVYefv9PnDjdcYC6ak7/f/xt2NC7VoZ6Odg3SxLQe1LA0sR+GkyqwRFXc1BaZqg=='; $packet = Ulink_TransportPacket::createFromJson($rawData); $this->assertNotNull($packet); $this->assertEquals(15, $packet->getClientId()); $this->assertNotNull($packet->getSignature()); $this->assertTrue($packet->validateAgainstKey($pubKey)); $request = Ulink_RequestFactory::createFromJson( Ulink_CryptoUtils::unseal($packet->getRequest(), $privKey) ); $this->assertInstanceof('Ulink_PaymentRequest', $request); $paymentRequest = $request; $this->assertEquals("34.90", (string)$paymentRequest->getAmount()); $this->assertEquals("EUR", $paymentRequest->getCurrency()); $order = $paymentRequest->getOrder(); $this->assertNotNull($order); $this->assertEquals(2, count($order->getItems())); $items = $order->getItems(); $orderItem1 = $items[0]; $orderItem2 = $items[1]; $this->assertEquals("Milk", $orderItem1->getName()); $this->assertEquals("Puhlqj ez", $orderItem1->getDescription()); $this->assertEquals("25.90", (string)$orderItem1->getOneItemPrice()); $this->assertEquals("Mja4ik", $orderItem2->getName()); $this->assertEquals("Puhlqj mja4", $orderItem2->getDescription()); $this->assertEquals("9.00", (string)$orderItem2->getOneItemPrice()); }