1 using System.Diagnostics.Contracts;
4 // Copyright (c) Microsoft Corporation. All rights reserved.
7 // <OWNER>Microsoft</OWNER>
14 namespace System.Security.Cryptography
16 [System.Runtime.InteropServices.ComVisible(true)]
17 public sealed class RijndaelManaged : Rijndael {
18 public RijndaelManaged () {
20 if (CryptoConfig.AllowOnlyFipsAlgorithms)
21 throw new InvalidOperationException(Environment.GetResourceString("Cryptography_NonCompliantFIPSAlgorithm"));
22 Contract.EndContractBlock();
23 #endif // FEATURE_CRYPTO
26 // #CoreCLRRijndaelModes
28 // On CoreCLR we limit the supported cipher modes and padding modes for the AES algorithm to a
29 // single hard coded value. This allows us to remove a lot of code by removing support for the
30 // uncommon cases and forcing everyone to use the same common padding and ciper modes:
32 // - CipherMode: CipherMode.CBC
33 // - PaddingMode: PaddingMode.PKCS7
35 public override ICryptoTransform CreateEncryptor (byte[] rgbKey, byte[] rgbIV) {
36 return NewEncryptor(rgbKey,
40 RijndaelManagedTransformMode.Encrypt);
43 public override ICryptoTransform CreateDecryptor (byte[] rgbKey, byte[] rgbIV) {
44 return NewEncryptor(rgbKey,
48 RijndaelManagedTransformMode.Decrypt);
51 public override void GenerateKey () {
52 KeyValue = Utils.GenerateRandom(KeySizeValue / 8);
55 public override void GenerateIV () {
56 IVValue = Utils.GenerateRandom(BlockSizeValue / 8);
59 private ICryptoTransform NewEncryptor (byte[] rgbKey,
63 RijndaelManagedTransformMode encryptMode) {
64 // Build the key if one does not already exist
66 rgbKey = Utils.GenerateRandom(KeySizeValue / 8);
69 // If not ECB mode, make sure we have an IV. In CoreCLR we do not support ECB, so we must have
70 // an IV in all cases.
72 if (mode != CipherMode.ECB) {
73 #endif // !FEATURE_CRYPTO
75 rgbIV = Utils.GenerateRandom(BlockSizeValue / 8);
79 #endif // !FEATURE_CRYPTO
81 // Create the encryptor/decryptor object
82 return new RijndaelManagedTransform (rgbKey,