1 // Licensed to the .NET Foundation under one or more agreements. 2 // The .NET Foundation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using System; 6 using System.Diagnostics; 7 8 using Internal.Cryptography; 9 10 namespace System.Security.Cryptography 11 { 12 public sealed partial class RSACng : RSA 13 { 14 /// <summary> 15 /// Creates a new RSACng object that will use the specified key. The key's 16 /// <see cref="CngKey.AlgorithmGroup" /> must be Rsa. This constructor 17 /// creates a copy of the key. Hence, the caller can safely dispose of the 18 /// passed in key and continue using the RSACng object. 19 /// </summary> 20 /// <param name="key">Key to use for RSA operations</param> 21 /// <exception cref="ArgumentException">if <paramref name="key" /> is not an RSA key</exception> 22 /// <exception cref="ArgumentNullException">if <paramref name="key" /> is null.</exception> RSACng(CngKey key)23 public RSACng(CngKey key) 24 { 25 if (key == null) 26 throw new ArgumentNullException(nameof(key)); 27 28 if (key.AlgorithmGroup != CngAlgorithmGroup.Rsa) 29 throw new ArgumentException(SR.Cryptography_ArgRSARequiresRSAKey, nameof(key)); 30 31 Key = CngAlgorithmCore.Duplicate(key); 32 } 33 Dispose(bool disposing)34 protected override void Dispose(bool disposing) 35 { 36 _core.Dispose(); 37 } 38 39 private CngAlgorithmCore _core; 40 } 41 } 42