-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDramaboxApp.php
More file actions
43 lines (36 loc) · 1.38 KB
/
DramaboxApp.php
File metadata and controls
43 lines (36 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
final class DramaboxApp {
private static $privateKey = null;
private static function initPrivateKey(): void {
if (self::$privateKey !== null) return;
try {
$pemFile = __DIR__ . '/private_key.pem';
if (!file_exists($pemFile)) {
throw new RuntimeException("Private key file not found: {$pemFile}");
}
$pem = file_get_contents($pemFile);
if ($pem === false) {
throw new RuntimeException("Failed to read private key file");
}
self::$privateKey = openssl_pkey_get_private($pem);
if (!self::$privateKey) {
throw new RuntimeException("Failed to load private key");
}
} catch (Throwable $e) {
error_log("[dramaboxapp] Failed to initialize private key: " . $e->getMessage());
self::$privateKey = null;
}
}
public static function sign(string $str): ?string {
if (self::$privateKey === null) self::initPrivateKey();
if (!self::$privateKey) return null;
$signature = '';
$ok = openssl_sign($str, $signature, self::$privateKey, OPENSSL_ALGO_SHA256);
if (!$ok) return null;
return base64_encode($signature);
}
public static function dramabox(string $str): ?string {
return self::sign($str);
}
}
?>