Created
May 7, 2015 13:17
-
-
Save cmbaughman/7281fbaae48e922eb727 to your computer and use it in GitHub Desktop.
Functions to decrypt and encrypt Wordpress passwords from plugin.
This file contains hidden or 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
<?php | |
/* These need to go in your custom plugin (or existing plugin) */ | |
private function encrypt($input_string, $key){ | |
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); | |
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); | |
$h_key = hash('sha256', $key, TRUE); | |
return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $h_key, $input_string, MCRYPT_MODE_ECB, $iv)); | |
} | |
private function decrypt($encrypted_input_string, $key){ | |
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); | |
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); | |
$h_key = hash('sha256', $key, TRUE); | |
return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $h_key, base64_decode($encrypted_input_string), MCRYPT_MODE_ECB, $iv)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment