Skip to content

Instantly share code, notes, and snippets.

@ahgood
Created December 10, 2018 21:25
Show Gist options
  • Save ahgood/d708e3763bdd4323a45e7cc454e6b7c9 to your computer and use it in GitHub Desktop.
Save ahgood/d708e3763bdd4323a45e7cc454e6b7c9 to your computer and use it in GitHub Desktop.
Common PHP encrypt decrypt
// encrypt
function encrypt(string $data, string $key, string $method) {
$encrypted = openssl_encrypt($data, $method, $key, OPENSSL_RAW_DATA);
$encrypted = base64_encode($encrypted);
return $encrypted;
}
// decrypt
function decrypt(string $data, string $key, string $method) {
$data = base64_decode($data);
$data = openssl_decrypt($data, $method, $key, OPENSSL_RAW_DATA);
return $data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment