Я знаю, что этот вопрос можно задать несколько раз и , есть также пример для захвата IV и TAG перед расшифровкой , но когда я его использую, он не работает!
Я пытаюсь использовать функцию «расшифровать» в отдельном файле, и когда я пытаюсь использовать эту функцию, я не вижу вывода. Ниже запутанный код - это метод, который я пытаюсь использовать для шифрования / дешифрования, но почему я не вижу вывода для дешифрования?
Если кто-нибудь знает ответ, пожалуйста, помогите мне. Большое спасибо.
<?php
class encryption{
private $KEY;
private $cipher = "aes-256-gcm";
private $ivlen;
private $IV;
private $options;
private $tag;
private $output = "";
private function Key(){
$this->KEY = openssl_random_pseudo_bytes (16);
return $this->KEY;
}
private function Iv(){
$this->IV = openssl_random_pseudo_bytes (16);
$this->IV = base64_encode($this->IV);
return $this->IV;
}
public function encrypt($string){
$ivlen = openssl_cipher_iv_length($this->cipher);
if (in_array($this->cipher, openssl_get_cipher_methods())){
$this->output = openssl_encrypt($string, $this->cipher, $this->Key(), $options=0, $this->Iv(), $this->tag);
$this->tag = base64_encode($this->tag);
}
return $this->output;
}
public function decrypt($string){
$this->tag = base64_decode($this->tag);
$dec_iv = base64_decode($this->Iv());
if (in_array($this->cipher, openssl_get_cipher_methods())){
$this->output = openssl_decrypt($string, $this->cipher, $this->Key(), $options=0, $dec_iv, $this->tag);
}
return $this->output;
}
}
?>