update rm deadcode
This commit is contained in:
@@ -7,13 +7,16 @@ class SignRSA
|
||||
protected string $key;
|
||||
protected ?string $private;
|
||||
protected string $public;
|
||||
protected ?string $previousKey;
|
||||
protected ?string $previousPublic;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->key = base64_decode(config('rsa.key'));
|
||||
$this->private = str_replace('\n', "\n", config('rsa.private'));
|
||||
$this->public = str_replace('\n', "\n", config('rsa.public'));
|
||||
|
||||
$this->previousKey = config('rsa.previous_key') ? base64_decode(config('rsa.previous_key')) : null;
|
||||
$this->previousPublic = config('rsa.previous_public') ? str_replace('\n', "\n", config('rsa.previous_public')) : null;
|
||||
}
|
||||
|
||||
|
||||
@@ -49,9 +52,14 @@ class SignRSA
|
||||
if (!$data) {
|
||||
return false;
|
||||
}
|
||||
$decrypted_data = $this->DecryptData(base64_decode($data), $this->key);
|
||||
$encrypted_data = base64_decode($data);
|
||||
$verified = $this->Verify_Sign((string) $this->DecryptData($encrypted_data, $this->key), $this->public);
|
||||
|
||||
return $this->Verify_Sign($decrypted_data);
|
||||
if ($verified === false && $this->previousKey && $this->previousPublic) {
|
||||
$verified = $this->Verify_Sign((string) $this->DecryptData($encrypted_data, $this->previousKey), $this->previousPublic);
|
||||
}
|
||||
|
||||
return $verified;
|
||||
}
|
||||
|
||||
private function DecryptData($encrypted_data, $random_key): bool|string
|
||||
@@ -59,7 +67,7 @@ class SignRSA
|
||||
return openssl_decrypt($encrypted_data, 'DES-EDE3', $random_key, OPENSSL_RAW_DATA);
|
||||
}
|
||||
|
||||
private function Verify_Sign($decrypted_data): array|string|false
|
||||
private function Verify_Sign(string $decrypted_data, string $public): string|false
|
||||
{
|
||||
$data_arr = explode('|', $decrypted_data);
|
||||
|
||||
@@ -67,19 +75,15 @@ class SignRSA
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isset($data_arr[1])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$signature = base64_decode($data_arr[1]);
|
||||
|
||||
unset($data_arr[1]);
|
||||
|
||||
$signature_data = implode('|', $data_arr);
|
||||
|
||||
$verify = openssl_verify($signature_data, $signature, $this->public, 'sha256WithRSAEncryption');
|
||||
$verify = openssl_verify($signature_data, $signature, $public, 'sha256WithRSAEncryption');
|
||||
|
||||
return $verify ? $signature_data : false;
|
||||
return $verify === 1 ? $signature_data : false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user