| | 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 | | internal class SecretKey : KeyVaultKey |
| | 10 | | { |
| | 11 | | private const string IdPropertyName = "id"; |
| | 12 | | private const string ValuePropertyName = "value"; |
| | 13 | | private const string ContentTypePropertyName = "contentType"; |
| | 14 | |
|
| 12 | 15 | | public SecretKey() |
| | 16 | | { |
| 12 | 17 | | Key = new JsonWebKey(new[] { KeyOperation.Encrypt, KeyOperation.Decrypt, KeyOperation.WrapKey, KeyOperation. |
| 12 | 18 | | { |
| 12 | 19 | | KeyType = Keys.KeyType.Oct, |
| 12 | 20 | | }; |
| 12 | 21 | | } |
| | 22 | |
|
| 0 | 23 | | public string ContentType { get; private set; } |
| | 24 | |
|
| | 25 | | internal override void ReadProperty(JsonProperty prop) |
| | 26 | | { |
| 16 | 27 | | switch (prop.Name) |
| | 28 | | { |
| | 29 | | case IdPropertyName: |
| 4 | 30 | | Key.Id = prop.Value.GetString(); |
| 4 | 31 | | Properties.Id = new Uri(Key.Id); |
| 4 | 32 | | KeyVaultIdentifier kvid = KeyVaultIdentifier.Parse(Properties.Id); |
| 4 | 33 | | Properties.Name = kvid.Name; |
| 4 | 34 | | Properties.VaultUri = kvid.VaultUri; |
| 4 | 35 | | Properties.Version = kvid.Version; |
| 4 | 36 | | break; |
| | 37 | |
|
| | 38 | | case ContentTypePropertyName: |
| 4 | 39 | | ContentType = prop.Value.GetString(); |
| 4 | 40 | | break; |
| | 41 | |
|
| | 42 | | case ValuePropertyName: |
| 4 | 43 | | byte[] keyBytes = Base64Url.Decode(prop.Value.GetString()); |
| 4 | 44 | | Key.K = keyBytes; |
| 4 | 45 | | break; |
| | 46 | |
|
| | 47 | | default: |
| 4 | 48 | | base.ReadProperty(prop); |
| | 49 | | break; |
| | 50 | | } |
| 4 | 51 | | } |
| | 52 | | } |
| | 53 | | } |