Skip to content

Instantly share code, notes, and snippets.

@cmbaughman
Created May 7, 2015 13:17
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmbaughman/7281fbaae48e922eb727 to your computer and use it in GitHub Desktop.
Save cmbaughman/7281fbaae48e922eb727 to your computer and use it in GitHub Desktop.
Functions to decrypt and encrypt Wordpress passwords from plugin.
<?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