Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.05 KB | None | 0 0
  1.         $ENCRYPTION_KEY = 's12qwe13q1sad32asd32as1d5qw4ed6as';
  2.         $ENCRYPTION_ALGORITHM = 'AES-256-CBC';
  3.  
  4.         function EncryptThis($ClearTextData) {
  5.             global $ENCRYPTION_KEY;
  6.             global $ENCRYPTION_ALGORITHM;
  7.             $EncryptionKey = base64_decode($ENCRYPTION_KEY);
  8.             $InitializationVector  = openssl_random_pseudo_bytes(openssl_cipher_iv_length($ENCRYPTION_ALGORITHM));
  9.             $EncryptedText = openssl_encrypt($ClearTextData, $ENCRYPTION_ALGORITHM, $EncryptionKey, 0, $InitializationVector);
  10.             return base64_encode($EncryptedText . '::' . $InitializationVector);
  11.         }
  12.         function DecryptThis($CipherData) {
  13.             global $ENCRYPTION_KEY;
  14.             global $ENCRYPTION_ALGORITHM;
  15.             $EncryptionKey = base64_decode($ENCRYPTION_KEY);
  16.             list($Encrypted_Data, $InitializationVector ) = array_pad(explode('::', base64_decode($CipherData), 2), 2, null);
  17.             return openssl_decrypt($Encrypted_Data, $ENCRYPTION_ALGORITHM, $EncryptionKey, 0, $InitializationVector);
  18.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement