Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private function encrypt( $data, $key ) {
- $salt = 'cH!swe!retReGu7W6bEDRup7usuDUh9THeD2CHeGE*ewr4n39=E@rAsp7c-Ph@pH';
- $iv_size = openssl_cipher_iv_length( "AES-256-CBC-HMAC-SHA256" );
- $hash = hash( 'sha256', $salt . $key . $salt );
- $iv = substr( $hash, strlen( $hash ) - $iv_size );
- $key = substr( $hash, 0, 32 );
- $encrypted = base64_encode( openssl_encrypt( $data, "AES-256-CBC-HMAC-SHA256", $key, OPENSSL_RAW_DATA, $iv ) );
- return $encrypted;
- }
- private function decrypt( $data, $key ) {
- $salt = 'cH!swe!retReGu7W6bEDRup7usuDUh9THeD2CHeGE*ewr4n39=E@rAsp7c-Ph@pH';
- $iv_size = openssl_cipher_iv_length( "AES-256-CBC-HMAC-SHA256" );
- $hash = hash( 'sha256', $salt . $key . $salt );
- $iv = substr( $hash, strlen( $hash ) - $iv_size );
- $key = substr( $hash, 0, 32 );
- $decrypted = openssl_decrypt( base64_decode( $data ), "AES-256-CBC-HMAC-SHA256", $key, OPENSSL_RAW_DATA, $iv );
- $decrypted = rtrim( $decrypted, "\0" );
- return $decrypted;
- }
- // code from here
- // https://stackoverflow.com/questions/45246461/convert-framework-from-mcrypt-to-openssl
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement