Skip to content
8 changes: 4 additions & 4 deletions example-app/app/Helpers/ParameterParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static function parseEncryptedParams(Request $request): array
}

$encFileDataBin = null;
if (!empty($encFileData)) {
if (! empty($encFileData)) {
if (strlen($encFileData) % 2 !== 0) {
throw new \InvalidArgumentException(
sprintf('Invalid %s parameter: must have even length', $paramNames['enc_file_data'])
Expand Down Expand Up @@ -154,7 +154,7 @@ private static function parseBulkMode(string $bulkParam, string $sdmmacParamName
}

// Remove the SDMMAC parameter suffix if present
$sdmmacSuffix = '&' . $sdmmacParamName . '=';
$sdmmacSuffix = '&'.$sdmmacParamName.'=';
$bulkParam = str_replace($sdmmacSuffix, '', $bulkParam);

// Validate hex string length is even
Expand Down Expand Up @@ -197,7 +197,7 @@ private static function parseBulkMode(string $bulkParam, string $sdmmacParamName
/**
* Detect encryption mode based on PICC data length.
*
* @param string $piccData Binary PICC data
* @param string $piccData Binary PICC data
* @return string 'AES' or 'LRP'
*/
private static function detectEncryptionMode(string $piccData): string
Expand All @@ -216,7 +216,7 @@ private static function detectEncryptionMode(string $piccData): string
/**
* Interpret tamper tag status from file data.
*
* @param string $fileData Binary file data
* @param string $fileData Binary file data
* @return array{status: string, color: string}|null
*/
public static function interpretTamperStatus(string $fileData): ?array
Expand Down
57 changes: 57 additions & 0 deletions example-app/app/Http/Controllers/BaseSDMController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers;

use KDuma\SDM\SDM;

abstract class BaseSDMController extends Controller
{
/**
* Get SDM instance.
*/
protected function getSDM(?string $uid = null): SDM
{
$factory = app('sdm.factory');

return $factory($uid);
}

/**
* Get master key from configuration.
*/
protected function getMasterKey(): string
{
$masterKeyHex = config('sdm.master_key');
$masterKey = hex2bin($masterKeyHex);

if ($masterKey === false) {
throw new \InvalidArgumentException('Invalid master key format');
}

return $masterKey;
}

/**
* Get encryption key.
*/
protected function getEncKey(): string
{
$masterKey = $this->getMasterKey();
$kdf = app(\KDuma\SDM\KeyDerivation::class);

return $kdf->deriveUndiversifiedKey($masterKey, 1);
}

/**
* Get MAC key for a specific UID.
*/
protected function getMacKey(string $uid): string
{
$masterKey = $this->getMasterKey();
$kdf = app(\KDuma\SDM\KeyDerivation::class);

return $kdf->deriveTagKey($masterKey, $uid, 2);
}
}
Loading