PHP code example of gorokhovdv / safetynet-verification
1. Go to this page and download the library: Download gorokhovdv/safetynet-verification 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/ */
gorokhovdv / safetynet-verification example snippets
\SafetyNet\Config\Config;
use \SafetyNet\Statement\Statement;
use \SafetyNet\Attestation;
use \SafetyNet\Verifier\VerifierType;
use \SafetyNet\Nonce;
use \SafetyNet\SafetyNetAttestationException;
$attestationStatement = new Statement('RAW-JWS-STATEMENT');
$nonce = new Nonce('Test-nonce');
try {
$attestationConfig = new Config([
Config::VERIFIER_TYPE => VerifierType::ONLINE(),
Config::VERIFIER_TIMESTAMP_DIFF => 10 * 60 * 1000,
Config::VERIFIER_CERTIFICATE_DIGEST_SHA256 => ['SHA-256-FINGERPRINT'],
Config::VERIFIER_PACKAGE_NAME => ['APK-NAME-FOR-TEST'],
Config::VERIFIER_API_KEY => 'GOOGLE-API-KEY',
Config::VERIFIER_HARDWARE_BACKED => true,
]);
$attestation = new Attestation($attestationConfig);
if ($attestation->verity($nonce, $attestationStatement)) {
echo 'Verification success!' . PHP_EOL;
} else {
echo 'Verification failed!' . PHP_EOL;
}
} catch (SafetyNetAttestationException $e) {
echo $e->getMessage() . PHP_EOL;
}
\SafetyNet\Config\Config;
use \SafetyNet\Statement\Statement;
use \SafetyNet\Attestation;
use \SafetyNet\Verifier\VerifierType;
use \SafetyNet\Nonce;
use \SafetyNet\SafetyNetAttestationException;
$attestationStatement = new Statement('RAW-JWS-STATEMENT');
$nonce = new Nonce('Test-nonce');
try {
$attestationConfig = new Config([
Config::VERIFIER_TYPE => VerifierType::OFFLINE(),
Config::VERIFIER_TIMESTAMP_DIFF => 10 * 60 * 1000,
Config::VERIFIER_CERTIFICATE_DIGEST_SHA256 => ['SHA-256-FINGERPRINT'],
Config::VERIFIER_PACKAGE_NAME => ['APK-NAME-FOR-TEST'],
Config::VERIFIER_HARDWARE_BACKED => true,
]);
$attestation = new Attestation($attestationConfig);
if ($attestation->verity($nonce, $attestationStatement)) {
echo 'Verification success!' . PHP_EOL;
} else {
echo 'Verification failed!' . PHP_EOL;
}
} catch (SafetyNetAttestationException $e) {
echo $e->getMessage() . PHP_EOL;
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.