Created
October 14, 2020 05:03
-
-
Save dougvann/ae94340b6bae5e72f328ff170706525f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function encryptData($data) { | |
$plainText = json_encode($data); | |
$bytesToBeEncrypted = $plainText; | |
$passwordBytes = utf8_encode("p@SSword"); | |
$passwordBytes = hash('sha256', $passwordBytes, true); | |
$saltBytes = array(1,2,3,4,5,6,7,8); | |
$saltBytesstring = ""; | |
for($i=0;$i<count($saltBytes);$i++){ | |
$saltBytesstring = $saltBytesstring.chr($saltBytes[$i]); | |
} | |
$hash = hash_pbkdf2("sha1", $passwordBytes, $saltBytesstring, 1000, 48, true); | |
$keyHash = substr($hash, 0, 32); | |
$ivHash = substr($hash, 32, 16); | |
$method = 'AES-256-CBC'; | |
$encrypted = replaceCharacters(base64_encode(openssl_encrypt($bytesToBeEncrypted, $method, $keyHash, OPENSSL_RAW_DATA, $ivHash))); | |
return $encrypted; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment