Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Keychain
- * @version 10-11-2024
- */
- function keychain($ct, $mt, $pw = '') {
- /**
- * Encrypt
- */
- if($mt === true) {
- $iv = openssl_random_pseudo_bytes(16);
- $pw = hash_pbkdf2('sha256', $pw, $iv, 1000, 32, true);
- $en = openssl_encrypt($ct, 'AES-256-CBC', $pw, OPENSSL_RAW_DATA, $iv);
- return base64_encode($iv . $en);
- }
- /**
- * Decrypt
- */
- if($mt === false) {
- $ct = base64_decode($ct);
- $iv = substr($ct, 0, 16);
- $pw = hash_pbkdf2('sha256', $pw, $iv, 1000, 32, true);
- $ct = substr($ct, 16);
- return openssl_decrypt($ct, 'AES-256-CBC', $pw, OPENSSL_RAW_DATA, $iv);
- }
- }
Add Comment
Please, Sign In to add comment