示例#1
0
 /**
  * Decrypt data originally returned from ::encrypt() using the two keys
  * that were originially passed into the ::encrypt() method.
  *
  * Parameters:
  * ciphertext - (string<binary>) Unencoded data returned from the
  *      ::encrypt() method
  * key - (string) master key used for the encryption originally
  * skey - (string_ sub key or namespace used originally for the
  *      encryption
  */
 function decrypt($ciphertext, $key, $skey = 'encryption')
 {
     if (!$key || !$ciphertext || $ciphertext[0] != '$') {
         return false;
     }
     list(, $crypt, $ciphertext) = explode('$', $ciphertext, 3);
     //Get crypto....  based on crypt tag.
     if (!$crypt || !($crypto = Crypto::get($crypt)) || !$crypto->exists()) {
         return false;
     }
     $crypto->setKeys($key, $skey);
     return $crypto->decrypt(base64_decode($ciphertext));
 }