sdk_php icon indicating copy to clipboard operation
sdk_php copied to clipboard

PHP Creating an API context error

Open jeraldpunx opened this issue 4 years ago • 5 comments

Steps to reproduce:

<?php
	require __DIR__ . '/vendor/autoload.php';
    use bunq\Context\ApiContext;
	use bunq\Util\BunqEnumApiEnvironmentType;

	$environmentType = BunqEnumApiEnvironmentType::SANDBOX(); // Can also be BunqEnumApiEnvironmentType::PRODUCTION();
	$apiKey = 'asdasdasdasd'; // Replace with your API key
	$deviceDescription = "JeraldPC"; // Replace with your device description
	$permittedIps = ['0.0.0.0']; // List the real expected IPs of this device or leave empty to use the current IP

	$apiContext = ApiContext::create(
	    $environmentType,
	    $apiKey,
	    $deviceDescription,
	    $permittedIps
	);

	BunqContext::loadApiContext($apiContext);

What should happen:

Create API Context

What happens:

Fatal error: Uncaught bunq\Exception\BunqException: Generating a new private key failed. See "http://php.net/manual/en/function.openssl-pkey-new.php" for more info. in D:\laragon\www\bunq\vendor\bunq\sdk_php\src\Security\KeyPair.php:66 Stack trace: #0 D:\laragon\www\bunq\vendor\bunq\sdk_php\src\Context\ApiContext.php(187): bunq\Security\KeyPair::generate() #1 D:\laragon\www\bunq\vendor\bunq\sdk_php\src\Context\ApiContext.php(178): bunq\Context\ApiContext->initializeInstallationContext() #2 D:\laragon\www\bunq\vendor\bunq\sdk_php\src\Context\ApiContext.php(119): bunq\Context\ApiContext->initialize('JeraldPC', Array) #3 D:\laragon\www\bunq\index.php(16): bunq\Context\ApiContext::create(Object(bunq\Util\BunqEnumApiEnvironmentType), 'a6785e1ff4f3964...', 'JeraldPC', Array) #4 {main} thrown in D:\laragon\www\bunq\vendor\bunq\sdk_php\src\Security\KeyPair.php on line 66

Traceback

SDK version and environment

  • Tested on 1.14.1
  • [check ] Sandbox
  • [ ] Production

jeraldpunx avatar Jan 27 '21 08:01 jeraldpunx

help, what is my problem here? I already have openSSL enabled in PHP

jeraldpunx avatar Jan 27 '21 11:01 jeraldpunx

help, what is my problem here? I already have openSSL enabled in PHP

Hi,

Can you maybe create (and test) a simple PHP-script with only the following contents?

<?php
$config = array(
    "digest_alg" => "sha512",
    "private_key_bits" => 2048,
    "private_key_type" => OPENSSL_KEYTYPE_RSA,
);
   
$opensslKeyPair = openssl_pkey_new($config);

Because it looks like it's failing on this part of the script

basst85 avatar Jan 27 '21 20:01 basst85

Check also this installation info of OpenSSL: https://www.php.net/manual/en/openssl.installation.php

basst85 avatar Jan 27 '21 20:01 basst85

I'm still having hardtime. The libcrypto exist already on my apache and php but still not works. image

jeraldpunx avatar Jan 27 '21 23:01 jeraldpunx

I'm still having hardtime. The libcrypto exist already on my apache and php but still not works.

Is OpenSSL active and enabled in the PHPinfo output? https://php.tutorials24x7.com/blog/how-to-configure-php-openssl-module-on-windows

And is the Window Environment Variable "OPENSSL_CONF" also set to the location of openssl.conf ? https://seegatesite.com/the-steps-how-to-install-openssl-on-xampp-windows/

basst85 avatar Jan 28 '21 07:01 basst85