Php 需要';openssl加密&x27;类内固定
这是一个带有解密和加密的简单类,下面的代码不起作用,我如何修复它Php 需要';openssl加密&x27;类内固定,php,class,encryption,Php,Class,Encryption,这是一个带有解密和加密的简单类,下面的代码不起作用,我如何修复它 class en{ const cipher = "aes-128-gcm"; const key = "sitekey"; function iv(){ return openssl_random_pseudo_bytes(openssl_cipher_iv_length(self::cipher)); } function encrypt($text,$iv){
class en{
const cipher = "aes-128-gcm";
const key = "sitekey";
function iv(){
return openssl_random_pseudo_bytes(openssl_cipher_iv_length(self::cipher));
}
function encrypt($text,$iv){
return openssl_encrypt($text, self::cipher, self::key, $options=0, $iv, $tag);
}
function decrypt($text,$iv){
return openssl_decrypt($text, self::cipher, self::key, $options=0, $iv, $tag);
}
}
$en = new en();
$iv = $en->iv();
$encrypted = $en->encrypt("message to be encrypted",$iv);
$decrypted = $en->decrypt($encrypted,$iv);
echo "iv: ".$iv."<br />";
echo "Encrypted: ".$encrypted."<br />";
echo "Decrypted: ".$decrypted."<br />";
en类{
const cipher=“aes-128-gcm”;
const key=“sitekey”;
职能四(){
返回openssl_随机_伪_字节(openssl_密码_iv_长度(self::cipher));
}
函数加密($text,$iv){
返回openssl_encrypt($text,self::cipher,self::key,$options=0,$iv,$tag);
}
函数解密($text,$iv){
返回openssl_decrypt($text,self::cipher,self::key,$options=0,$iv,$tag);
}
}
$en=新的en();
$iv=$en->iv();
$encrypted=$en->encrypt(“要加密的邮件”,$iv);
$decrypted=$en->decrypt($encrypted,$iv);
回声“iv:.$iv.”
”;
echo“加密:.”加密“
”;
echo“已解密:.$已解密。”
;
使用openssl加密和openssl解密功能时,
您有$tag变量作为参数传递。
但是$tag并没有在任何地方声明
如果删除对$tag的2个引用并将加密方法更改为
aes-128-cbc
代码是有效的