PHP
Encrypting/Decrypting data with our backend SDKs may expose you to greater compliance burden because your server needs to handle plaintext data. Instead, we recommend using Relay or our Client-Side SDKs to encrypt data.
Getting started
Dependencies
The Evervault SDK requires PHP 7.1.0 or later.
The bindings also require the following extensions; openssl, curl, json, and mbstring.
If you install the bindings using Composer, these should automatically be installed. Otherwise, ensure that the extensions are available on your system.
Install the SDK
Our PHP SDK is distributed via Composer, or it can be installed manually.
You can install the Evervault PHP bindings using Composer. Simply run the following command:
Then to use the bindings, use Composer's autoload:
Initialize the SDK
The SDK needs to be initialized with an App's ID and API key. If you don't have one yet, you can get one by creating an App in the Evervault Dashboard.
Encrypt a string
Now that the SDK is initialized, we can encrypt a string.
Reference
encrypt()
Encrypts data using Evervault Encryption. Evervault Strings can be used across all of our products. To encrypt data using the PHP SDK, simply pass a string or array into the encrypt() method. The encrypted data can be stored in your database as normal and can be used with any of Evervault’s other services.
decrypt()
Decrypts the data previously encrypted with the encrypt() function or through Relay. An API key with the decrypt permission must be used to perform this operation.
PCI Compliance
createClientsideDecryptToken()
Client Side Decrypt Tokens are versatile and short-lived tokens that frontend applications can utilise to decrypt data previously encrypted through Evervault. Client Side Decrypt Tokens are restricted to specific payloads.
By default, a Client Side Decrypt Token will live for 5 minutes into the future. The maximum time to live of the token is 10 minutes into the future.
Parameters
The payload containing encrypted data that the token will be used to decrypt.
The time the token will expire in Epoch seconds. Defaults to 5 minutes in the future.
run()
Lets you invoke an Evervault Function with a given payload.
Parameters
The name of the function to invoke.
The payload to pass to the function.
The run() function returns an associative array. This array includes a unique run ID, the status of the execution denoted as success or failure, and, in cases of a successful run, the output generated by the function.
createRunToken()
Creates a single use, time bound token (5 minutes) for invoking an Evervault Function with a given payload. If the payload is an empty object, the Run Token will be valid for any payload. Run Tokens can be used to invoke an Evervault Function client-side without providing a sensitive API Key.
Parameters
The name of the function to invoke.
Payload that the token can be used with.
When you create a Run Token, the SDK will return a JSON object containing your token which can then be passed to your client-side application.
Run Tokens can then be used to authenticate Function runs from the client-side.
The payload used to invoke your Function must be identical to the payload used to create the Run Token.
enableOutboundRelay()
Configures your application to proxy HTTP requests using Relay for any requests to Relay destinations sent using the cURL handler provided.
Relay must be enabled for a CurlHandle after the destination URL has been set, and before curl_exec() is called.