public function toJSON()
{
$json = $this->getJSONBase();
$json['recipients'] = [];
foreach ($this->getRecipients() as $recipient) {
$temp = [];
if (!empty($recipient->getHeaders())) {
$temp['header'] = $recipient->getHeaders();
}
if (!empty($recipient->getEncryptedKey())) {
$temp['encrypted_key'] = Base64Url::encode($recipient->getEncryptedKey());
}
$json['recipients'][] = $temp;
}
return json_encode($json);
}