/// <summary> /// Adds additional data to encrypted data. Additional data is not protected, but it isn't added in plain text either. /// </summary> /// <param name="encryptedData">The encrypted data to which to add additional data.</param> /// <param name="additionalData">The additional data to add. Dictionary items where key or value is null or empty will be ignored/</param> /// <param name="destination">Stream to which to write encrypted data with added additional data</param> public static void AddAdditionalData(Stream encryptedData, Dictionary <string, string> additionalData, Stream destination) { if (additionalData == null) { throw new ArgumentNullException(nameof(additionalData)); } byte[] dataBytes = new AdditionalData(additionalData).GetBytes(); CryptoContainer.WriteAdditionalData(encryptedData, dataBytes, destination); }
/// <summary> /// Reads the additional data from encrypted data if present. /// </summary> /// <param name="encryptedData">The encrypted data.</param> /// <returns>Additional data</returns> public static Dictionary <string, string> ReadAdditionalData(Stream encryptedData) { byte[] data = CryptoContainer.ReadAdditionalData(encryptedData); return(AdditionalData.LoadFromBytes(data).Data); }