decryptHealthElement method

Future<DecryptedHealthElementDto> decryptHealthElement(
  1. String myId,
  2. HealthElementDto healthElementDto
)

Implementation

Future<DecryptedHealthElementDto> decryptHealthElement(String myId, HealthElementDto healthElementDto) async {
  final String? es = healthElementDto.encryptedSelf;

  if (es != null) {
    final secret = (await this.crypto.decryptEncryptionKeys(myId, healthElementDto.encryptionKeys)).firstOrNull?.formatAsKey().fromHexString();

    if (secret == null) {
      throw FormatException("Cannot get encryption key fo ${healthElementDto.id} and hcp $myId");
    }
    return this.unmarshaller(healthElementDto, base64.decoder.convert(es).decryptAES(secret));
  } else {
    return this.unmarshaller(healthElementDto, null);
  }
}