| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System.Text.Json; |
| | 5 | |
|
| | 6 | | namespace Azure.Security.KeyVault.Keys.Cryptography |
| | 7 | | { |
| | 8 | | /// <summary> |
| | 9 | | /// Represents information about an encryption operation. |
| | 10 | | /// </summary> |
| | 11 | | public class EncryptResult : IJsonDeserializable |
| | 12 | | { |
| | 13 | | private const string KeyIdPropertyName = "kid"; |
| | 14 | | private const string CiphertextPropertyName = "value"; |
| | 15 | |
|
| 24 | 16 | | internal EncryptResult() |
| | 17 | | { |
| 24 | 18 | | } |
| | 19 | |
|
| | 20 | | /// <summary> |
| | 21 | | /// Gets the <see cref="KeyProperties.Id"/> of the <see cref="KeyVaultKey"/> used to encrypt. This must be store |
| | 22 | | /// </summary> |
| 36 | 23 | | public string KeyId { get; internal set; } |
| | 24 | |
|
| | 25 | | /// <summary> |
| | 26 | | /// Gets the ciphertext that is the result of the encryption. |
| | 27 | | /// </summary> |
| 48 | 28 | | public byte[] Ciphertext { get; internal set; } |
| | 29 | |
|
| | 30 | | /// <summary> |
| | 31 | | /// Gets the <see cref="EncryptionAlgorithm"/> used for encryption. This must be stored alongside the <see cref= |
| | 32 | | /// </summary> |
| 36 | 33 | | public EncryptionAlgorithm Algorithm { get; internal set; } |
| | 34 | |
|
| | 35 | | void IJsonDeserializable.ReadProperties(JsonElement json) |
| | 36 | | { |
| 144 | 37 | | foreach (JsonProperty prop in json.EnumerateObject()) |
| | 38 | | { |
| 48 | 39 | | switch (prop.Name) |
| | 40 | | { |
| | 41 | | case KeyIdPropertyName: |
| 24 | 42 | | KeyId = prop.Value.GetString(); |
| 24 | 43 | | break; |
| | 44 | | case CiphertextPropertyName: |
| 24 | 45 | | Ciphertext = Base64Url.Decode(prop.Value.GetString()); |
| | 46 | | break; |
| | 47 | | } |
| | 48 | | } |
| 24 | 49 | | } |
| | 50 | | } |
| | 51 | | } |