Skip to content

Instantly share code, notes, and snippets.

@Achterstraat
Created February 15, 2019 08:15
Show Gist options
  • Save Achterstraat/ab25a03c84b4716b5edd724e57f027f4 to your computer and use it in GitHub Desktop.
Save Achterstraat/ab25a03c84b4716b5edd724e57f027f4 to your computer and use it in GitHub Desktop.
Extremely simple cryptor
function secret($string, $action = 'encrypt', $secret = 'random', $host = 'achterstraat.com', $method = 'AES-256-CBC')
{
switch($action)
{
case 'decrypt': {
return openssl_decrypt(base64_decode($string), $method, hash('sha256', $secret), 0, mb_substr(hash('sha256', $host), 0, 16));
}
default: {
return base64_encode(openssl_encrypt($string, $method, hash('sha256', $secret), 0, mb_substr(hash('sha256', $host), 0, 16)));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment