-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Expand file tree
/
Copy pathRijndaelImplementation.cs
More file actions
98 lines (84 loc) · 3.33 KB
/
RijndaelImplementation.cs
File metadata and controls
98 lines (84 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Diagnostics;
using System.Security.Cryptography;
namespace Internal.Cryptography
{
/// <summary>
/// Internal implementation of Rijndael.
/// This class is returned from Rijndael.Create() instead of the public RijndaelManaged to
/// be consistent with the rest of the static Create() methods which return opaque types.
/// They both have the same implementation.
/// </summary>
[Obsolete(Obsoletions.RijndaelMessage, DiagnosticId = Obsoletions.RijndaelDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
internal sealed class RijndaelImplementation : Rijndael
{
private readonly Aes _impl;
internal RijndaelImplementation()
{
LegalBlockSizesValue = new KeySizes[] { new KeySizes(minSize: 128, maxSize: 128, skipSize: 0) };
// This class wraps Aes
_impl = Aes.Create();
_impl.FeedbackSize = 128;
}
public override int BlockSize
{
get { return _impl.BlockSize; }
set
{
Debug.Assert(BlockSizeValue == 128);
// Values which were legal in .NET Framework RijndaelManaged but not here in this wrapper type
if (value == 192 || value == 256)
throw new PlatformNotSupportedException(SR.Cryptography_Rijndael_BlockSize);
// Any other invalid block size will get the normal "invalid block size" exception.
if (value != 128)
throw new CryptographicException(SR.Cryptography_Rijndael_BlockSize);
}
}
public override int FeedbackSize
{
get => _impl.FeedbackSize;
set => _impl.FeedbackSize = value;
}
public override byte[] IV
{
get { return _impl.IV; }
set { _impl.IV = value; }
}
public override byte[] Key
{
get { return _impl.Key; }
set { _impl.Key = value; }
}
public override int KeySize
{
get { return _impl.KeySize; }
set { _impl.KeySize = value; }
}
public override CipherMode Mode
{
get { return _impl.Mode; }
set { _impl.Mode = value; }
}
public override PaddingMode Padding
{
get { return _impl.Padding; }
set { _impl.Padding = value; }
}
public override KeySizes[] LegalKeySizes => _impl.LegalKeySizes;
public override ICryptoTransform CreateEncryptor() => _impl.CreateEncryptor();
public override ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[]? rgbIV) => _impl.CreateEncryptor(rgbKey, rgbIV);
public override ICryptoTransform CreateDecryptor() => _impl.CreateDecryptor();
public override ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[]? rgbIV) => _impl.CreateDecryptor(rgbKey, rgbIV);
public override void GenerateIV() => _impl.GenerateIV();
public override void GenerateKey() => _impl.GenerateKey();
protected override void Dispose(bool disposing)
{
if (disposing)
{
_impl.Dispose();
}
}
}
}