public static function get_challenge($user) { // Return error if any required parameter is missing if (!isset($user['random']) || !isset($user['public_key'])) { return false; } $user['public_key'] = TrustAuth::fix_key($user['public_key']); // Load the key into the engine $rsa = new Crypt_RSA(); $rsa->loadKey($user['public_key']); $rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1); $pre_master_secret = TrustAuth::get_pre_master_secret(); $server_random = TrustAuth::get_server_random(); // Encrypt the pre_master_secret and convert it to hex $encrypted_secret = bin2hex($rsa->encrypt($pre_master_secret)); $encrypted_random = bin2hex($rsa->encrypt($server_random)); // Encode the encrypted secret as json return array('status' => true, 'json' => json_encode(array('secret' => $encrypted_secret, 'random' => $encrypted_random, 'status' => TrustAuth::$status['auth'])), 'server' => array('random' => $server_random, 'pre_master_secret' => $pre_master_secret)); }