Skip to content

Instantly share code, notes, and snippets.

@ahgood
Created December 10, 2018 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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