PHP code example of roundly-consulting / crypto-for-laravel
1. Go to this page and download the library: Download roundly-consulting/crypto-for-laravel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
roundly-consulting / crypto-for-laravel example snippets
use RoundlyConsulting\Crypto\Facades\Crypto;
use RoundlyConsulting\Crypto\Signature\Algorithm;
$key = Crypto::keys()->ec()->fromStorageOrGenerate('local', 'keys/jwt.pem'); // P-256, created on first boot
$token = Crypto::jws()->sign(
['kid' => 'k1'],
['sub' => 'alice', 'exp' => now()->addHour()->timestamp],
Crypto::es($key),
);
$claims = Crypto::jws()->verify($token, Crypto::es($key), Algorithm::ES256);
$claims->assertTemporal(leeway: 30); // throws once expired
$claims->string('sub'); // "alice"
$expected = 'sha256='.Crypto::hmac()->signHex($request->getContent(), $webhookSecret);
Crypto::constantTimeEquals($expected, $request->header('X-Hub-Signature-256', ''));
$dataKey = Crypto::randomBytes(32);
$sealed = Crypto::aes256Gcm()->seal($dataKey, $iban, associatedData: 'invoices:42');
$iban = Crypto::aes256Gcm()->open($dataKey, $sealed, associatedData: 'invoices:42');
$secret = Crypto::randomSecret(); // base32, for an authenticator app
Crypto::provisioningUri($secret, '[email protected]', 'Acme Inc');
Crypto::totp()->verify($secret, $code); // the matched time step, or false
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.