namespace System.Security.Cryptography {
-#if NET_2_0
[ComVisible (true)]
-#endif
public abstract class SymmetricAlgorithm : IDisposable {
protected int BlockSizeValue;
- protected int FeedbackSizeValue;
protected byte[] IVValue;
protected int KeySizeValue;
protected byte[] KeyValue;
protected KeySizes[] LegalBlockSizesValue;
protected KeySizes[] LegalKeySizesValue;
- protected CipherMode ModeValue;
- protected PaddingMode PaddingValue;
+ protected int FeedbackSizeValue;
+ protected CipherMode ModeValue;
+ protected PaddingMode PaddingValue;
private bool m_disposed;
-#if NET_2_0
protected SymmetricAlgorithm ()
-#else
- public SymmetricAlgorithm ()
-#endif
{
ModeValue = CipherMode.CBC;
PaddingValue = PaddingMode.PKCS7;
- m_disposed = false;
- }
-
- ~SymmetricAlgorithm ()
- {
- Dispose (false);
}
- public void Clear()
+#if NET_4_0
+ public void Dispose ()
+#else
+ void IDisposable.Dispose ()
+#endif
{
Dispose (true);
+ GC.SuppressFinalize (this); // Finalization is now unnecessary
}
- void IDisposable.Dispose ()
+ public void Clear()
{
Dispose (true);
- GC.SuppressFinalize (this); // Finalization is now unnecessary
}
protected virtual void Dispose (bool disposing)
public virtual int FeedbackSize {
get { return this.FeedbackSizeValue; }
set {
-#if NET_2_0
if ((value <= 0) || (value > this.BlockSizeValue)) {
-#else
- if (value > this.BlockSizeValue) {
-#endif
throw new CryptographicException (
Locale.GetText ("feedback size larger than block size"));
}
+ if ((value & 3) != 0) {
+ throw new CryptographicException (
+ Locale.GetText ("feedback size must be a multiple of 8 (bits)"));
+ }
this.FeedbackSizeValue = value;
}
}
set {
if (value == null)
throw new ArgumentNullException ("IV");
-#if NET_2_0
// 2.0 is stricter for IV length - which is bad for IV-less stream ciphers like RC4
if ((value.Length << 3) != this.BlockSizeValue) {
throw new CryptographicException (
Locale.GetText ("IV length is different than block size"));
}
-#else
- if ((value.Length << 3) > this.BlockSizeValue) {
- throw new CryptographicException (
- Locale.GetText ("IV length cannot be larger than block size"));
- }
-#endif
this.IVValue = (byte[]) value.Clone ();
}
}
// LAMESPEC: Default is Rijndael - not TripleDES
public static SymmetricAlgorithm Create ()
{
+#if FULL_AOT_RUNTIME
+ return new System.Security.Cryptography.RijndaelManaged ();
+#else
return Create ("System.Security.Cryptography.SymmetricAlgorithm");
+#endif
}
public static SymmetricAlgorithm Create (string algName)