| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. See License.txt in the project root for |
| | 3 | | // license information. |
| | 4 | |
|
| | 5 | | using System; |
| | 6 | | using System.Security.Cryptography; |
| | 7 | |
|
| | 8 | | namespace Microsoft.Azure.KeyVault.Cryptography.Algorithms |
| | 9 | | { |
| | 10 | | /// <summary> |
| | 11 | | /// JWE A256KW: https://tools.ietf.org/html/rfc7518#section-4.4 |
| | 12 | | /// </summary> |
| | 13 | | public class AesKw256 : AesKw |
| | 14 | | { |
| | 15 | | public const string AlgorithmName = "A256KW"; |
| | 16 | |
|
| | 17 | | const int KeySizeInBytes = 256 >> 3; |
| | 18 | |
|
| | 19 | | public AesKw256() |
| 6 | 20 | | : base( AlgorithmName ) |
| | 21 | | { |
| 6 | 22 | | } |
| | 23 | |
|
| | 24 | | public override ICryptoTransform CreateDecryptor( byte[] key, byte[] iv ) |
| | 25 | | { |
| 8 | 26 | | if ( key == null ) |
| 0 | 27 | | throw new ArgumentNullException( "key" ); |
| | 28 | |
|
| 8 | 29 | | if ( key.Length < KeySizeInBytes ) |
| 0 | 30 | | throw new ArgumentOutOfRangeException( "key", "key must be at least 256 bits long" ); |
| | 31 | |
|
| 8 | 32 | | return base.CreateDecryptor( key.Take( KeySizeInBytes ), iv ); |
| | 33 | | } |
| | 34 | |
|
| | 35 | | public override ICryptoTransform CreateEncryptor( byte[] key, byte[] iv ) |
| | 36 | | { |
| 8 | 37 | | if ( key == null ) |
| 0 | 38 | | throw new ArgumentNullException( "key" ); |
| | 39 | |
|
| 8 | 40 | | if ( key.Length < KeySizeInBytes ) |
| 0 | 41 | | throw new ArgumentOutOfRangeException( "key", "key must be at least 256 bits long" ); |
| | 42 | |
|
| 8 | 43 | | return base.CreateEncryptor( key.Take( KeySizeInBytes ), iv ); |
| | 44 | | } |
| | 45 | | } |
| | 46 | | } |