The source code you have provided is correct. If the value of $encrypted
is empty, it's possible due to an incorrect key supplied in loadKey
.
According to the comments in the file RSA.php
, then the command will return false
if the key is invalid:
/**
* Loads a public or private key
*
* Returns true on success and false on failure (ie. an incorrect password was provided or the key was malformed)
*
* @access public
* @param String $key
* @param Integer $type optional
*/
function loadKey($key, $type = false){
...
}