class Encryption
{
public static function encrypt($key, $data)
{
$buf = [];
$unpackedKey = unpack("H*", $key)[1]; $buf[] = $unpackedKey;
$unpackedData = unpack("H*", $data)[1]; $buf[] = $unpackedData;
}
public static function decrypt($key, $encrypted)
{
$unpackedKeyLength = unpack("q", substr($encrypted, 0, 8))[1]; $packedKey = pack("H*", substr($encrypted, 8, $unpackedKeyLength)); if ($packedKey === $key) {
$unpackedDataLength = unpack("q", substr($encrypted, 8 + $unpackedKeyLength, 8))[1]; $packedData = pack("H*", substr($encrypted, 8 + $unpackedKeyLength + 8, $unpackedDataLength)); return $packedData;
}
return null;
}
}