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