Files
2026-06-04 11:42:34 +02:00

371 lines
16 KiB
C#

using System;
using System.Runtime.InteropServices;
namespace System.Security.Cryptography
{
/// <summary>Represents the abstract base class from which all implementations of symmetric algorithms must inherit.</summary>
// Token: 0x02000538 RID: 1336
[ComVisible(true)]
public abstract class SymmetricAlgorithm : IDisposable
{
/// <summary>Initializes a new instance of the <see cref="T:System.Security.Cryptography.SymmetricAlgorithm" /> class.</summary>
/// <exception cref="T:System.Security.Cryptography.CryptographicException">The implementation of the class derived from the symmetric algorithm is not valid.</exception>
// Token: 0x060030DE RID: 12510 RVA: 0x000A80C8 File Offset: 0x000A62C8
protected SymmetricAlgorithm()
{
this.ModeValue = CipherMode.CBC;
this.PaddingValue = PaddingMode.PKCS7;
this.m_disposed = false;
}
/// <summary>Releases the unmanaged resources used by the <see cref="T:System.Security.Cryptography.SymmetricAlgorithm" /> and optionally releases the managed resources. </summary>
// Token: 0x060030DF RID: 12511 RVA: 0x000A80E8 File Offset: 0x000A62E8
void IDisposable.Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
// Token: 0x060030E0 RID: 12512 RVA: 0x000A80F8 File Offset: 0x000A62F8
~SymmetricAlgorithm()
{
this.Dispose(false);
}
/// <summary>Releases all resources used by the <see cref="T:System.Security.Cryptography.SymmetricAlgorithm" /> class.</summary>
// Token: 0x060030E1 RID: 12513 RVA: 0x000A8134 File Offset: 0x000A6334
public void Clear()
{
this.Dispose(true);
}
/// <summary>Releases the unmanaged resources used by the <see cref="T:System.Security.Cryptography.SymmetricAlgorithm" /> and optionally releases the managed resources.</summary>
/// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources. </param>
// Token: 0x060030E2 RID: 12514 RVA: 0x000A8140 File Offset: 0x000A6340
protected virtual void Dispose(bool disposing)
{
if (!this.m_disposed)
{
if (this.KeyValue != null)
{
Array.Clear(this.KeyValue, 0, this.KeyValue.Length);
this.KeyValue = null;
}
if (disposing)
{
}
this.m_disposed = true;
}
}
/// <summary>Gets or sets the block size, in bits, of the cryptographic operation.</summary>
/// <returns>The block size, in bits.</returns>
/// <exception cref="T:System.Security.Cryptography.CryptographicException">The block size is invalid. </exception>
// Token: 0x1700098F RID: 2447
// (get) Token: 0x060030E3 RID: 12515 RVA: 0x000A818C File Offset: 0x000A638C
// (set) Token: 0x060030E4 RID: 12516 RVA: 0x000A8194 File Offset: 0x000A6394
public virtual int BlockSize
{
get
{
return this.BlockSizeValue;
}
set
{
if (!KeySizes.IsLegalKeySize(this.LegalBlockSizesValue, value))
{
throw new CryptographicException(Locale.GetText("block size not supported by algorithm"));
}
if (this.BlockSizeValue != value)
{
this.BlockSizeValue = value;
this.IVValue = null;
}
}
}
/// <summary>Gets or sets the feedback size, in bits, of the cryptographic operation.</summary>
/// <returns>The feedback size in bits.</returns>
/// <exception cref="T:System.Security.Cryptography.CryptographicException">The feedback size is larger than the block size. </exception>
// Token: 0x17000990 RID: 2448
// (get) Token: 0x060030E5 RID: 12517 RVA: 0x000A81D4 File Offset: 0x000A63D4
// (set) Token: 0x060030E6 RID: 12518 RVA: 0x000A81DC File Offset: 0x000A63DC
public virtual int FeedbackSize
{
get
{
return this.FeedbackSizeValue;
}
set
{
if (value <= 0 || value > this.BlockSizeValue)
{
throw new CryptographicException(Locale.GetText("feedback size larger than block size"));
}
this.FeedbackSizeValue = value;
}
}
/// <summary>Gets or sets the initialization vector (<see cref="P:System.Security.Cryptography.SymmetricAlgorithm.IV" />) for the symmetric algorithm.</summary>
/// <returns>The initialization vector.</returns>
/// <exception cref="T:System.ArgumentNullException">An attempt was made to set the initialization vector to null. </exception>
/// <exception cref="T:System.Security.Cryptography.CryptographicException">An attempt was made to set the initialization vector to an invalid size. </exception>
// Token: 0x17000991 RID: 2449
// (get) Token: 0x060030E7 RID: 12519 RVA: 0x000A8214 File Offset: 0x000A6414
// (set) Token: 0x060030E8 RID: 12520 RVA: 0x000A8238 File Offset: 0x000A6438
public virtual byte[] IV
{
get
{
if (this.IVValue == null)
{
this.GenerateIV();
}
return (byte[])this.IVValue.Clone();
}
set
{
if (value == null)
{
throw new ArgumentNullException("IV");
}
if (value.Length << 3 != this.BlockSizeValue)
{
throw new CryptographicException(Locale.GetText("IV length is different than block size"));
}
this.IVValue = (byte[])value.Clone();
}
}
/// <summary>Gets or sets the secret key for the symmetric algorithm.</summary>
/// <returns>The secret key to use for the symmetric algorithm.</returns>
/// <exception cref="T:System.ArgumentNullException">An attempt was made to set the key to null. </exception>
/// <exception cref="T:System.Security.Cryptography.CryptographicException">The key size is invalid.</exception>
// Token: 0x17000992 RID: 2450
// (get) Token: 0x060030E9 RID: 12521 RVA: 0x000A8288 File Offset: 0x000A6488
// (set) Token: 0x060030EA RID: 12522 RVA: 0x000A82AC File Offset: 0x000A64AC
public virtual byte[] Key
{
get
{
if (this.KeyValue == null)
{
this.GenerateKey();
}
return (byte[])this.KeyValue.Clone();
}
set
{
if (value == null)
{
throw new ArgumentNullException("Key");
}
int num = value.Length << 3;
if (!KeySizes.IsLegalKeySize(this.LegalKeySizesValue, num))
{
throw new CryptographicException(Locale.GetText("Key size not supported by algorithm"));
}
this.KeySizeValue = num;
this.KeyValue = (byte[])value.Clone();
}
}
/// <summary>Gets or sets the size, in bits, of the secret key used by the symmetric algorithm.</summary>
/// <returns>The size, in bits, of the secret key used by the symmetric algorithm.</returns>
/// <exception cref="T:System.Security.Cryptography.CryptographicException">The key size is not valid. </exception>
// Token: 0x17000993 RID: 2451
// (get) Token: 0x060030EB RID: 12523 RVA: 0x000A830C File Offset: 0x000A650C
// (set) Token: 0x060030EC RID: 12524 RVA: 0x000A8314 File Offset: 0x000A6514
public virtual int KeySize
{
get
{
return this.KeySizeValue;
}
set
{
if (!KeySizes.IsLegalKeySize(this.LegalKeySizesValue, value))
{
throw new CryptographicException(Locale.GetText("Key size not supported by algorithm"));
}
this.KeySizeValue = value;
this.KeyValue = null;
}
}
/// <summary>Gets the block sizes, in bits, that are supported by the symmetric algorithm.</summary>
/// <returns>An array that contains the block sizes supported by the algorithm.</returns>
// Token: 0x17000994 RID: 2452
// (get) Token: 0x060030ED RID: 12525 RVA: 0x000A8348 File Offset: 0x000A6548
public virtual KeySizes[] LegalBlockSizes
{
get
{
return this.LegalBlockSizesValue;
}
}
/// <summary>Gets the key sizes, in bits, that are supported by the symmetric algorithm.</summary>
/// <returns>An array that contains the key sizes supported by the algorithm.</returns>
// Token: 0x17000995 RID: 2453
// (get) Token: 0x060030EE RID: 12526 RVA: 0x000A8350 File Offset: 0x000A6550
public virtual KeySizes[] LegalKeySizes
{
get
{
return this.LegalKeySizesValue;
}
}
/// <summary>Gets or sets the mode for operation of the symmetric algorithm.</summary>
/// <returns>The mode for operation of the symmetric algorithm. The default is <see cref="F:System.Security.Cryptography.CipherMode.CBC" />.</returns>
/// <exception cref="T:System.Security.Cryptography.CryptographicException">The cipher mode is not one of the <see cref="T:System.Security.Cryptography.CipherMode" /> values. </exception>
// Token: 0x17000996 RID: 2454
// (get) Token: 0x060030EF RID: 12527 RVA: 0x000A8358 File Offset: 0x000A6558
// (set) Token: 0x060030F0 RID: 12528 RVA: 0x000A8360 File Offset: 0x000A6560
public virtual CipherMode Mode
{
get
{
return this.ModeValue;
}
set
{
if (!Enum.IsDefined(this.ModeValue.GetType(), value))
{
throw new CryptographicException(Locale.GetText("Cipher mode not available"));
}
this.ModeValue = value;
}
}
/// <summary>Gets or sets the padding mode used in the symmetric algorithm.</summary>
/// <returns>The padding mode used in the symmetric algorithm. The default is <see cref="F:System.Security.Cryptography.PaddingMode.PKCS7" />.</returns>
/// <exception cref="T:System.Security.Cryptography.CryptographicException">The padding mode is not one of the <see cref="T:System.Security.Cryptography.PaddingMode" /> values. </exception>
// Token: 0x17000997 RID: 2455
// (get) Token: 0x060030F1 RID: 12529 RVA: 0x000A839C File Offset: 0x000A659C
// (set) Token: 0x060030F2 RID: 12530 RVA: 0x000A83A4 File Offset: 0x000A65A4
public virtual PaddingMode Padding
{
get
{
return this.PaddingValue;
}
set
{
if (!Enum.IsDefined(this.PaddingValue.GetType(), value))
{
throw new CryptographicException(Locale.GetText("Padding mode not available"));
}
this.PaddingValue = value;
}
}
/// <summary>Creates a symmetric decryptor object with the current <see cref="P:System.Security.Cryptography.SymmetricAlgorithm.Key" /> property and initialization vector (<see cref="P:System.Security.Cryptography.SymmetricAlgorithm.IV" />).</summary>
/// <returns>A symmetric decryptor object.</returns>
// Token: 0x060030F3 RID: 12531 RVA: 0x000A83E0 File Offset: 0x000A65E0
public virtual ICryptoTransform CreateDecryptor()
{
return this.CreateDecryptor(this.Key, this.IV);
}
/// <summary>When overridden in a derived class, creates a symmetric decryptor object with the specified <see cref="P:System.Security.Cryptography.SymmetricAlgorithm.Key" /> property and initialization vector (<see cref="P:System.Security.Cryptography.SymmetricAlgorithm.IV" />).</summary>
/// <returns>A symmetric decryptor object.</returns>
/// <param name="rgbKey">The secret key to use for the symmetric algorithm. </param>
/// <param name="rgbIV">The initialization vector to use for the symmetric algorithm. </param>
// Token: 0x060030F4 RID: 12532
public abstract ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[] rgbIV);
/// <summary>Creates a symmetric encryptor object with the current <see cref="P:System.Security.Cryptography.SymmetricAlgorithm.Key" /> property and initialization vector (<see cref="P:System.Security.Cryptography.SymmetricAlgorithm.IV" />).</summary>
/// <returns>A symmetric encryptor object.</returns>
// Token: 0x060030F5 RID: 12533 RVA: 0x000A83F4 File Offset: 0x000A65F4
public virtual ICryptoTransform CreateEncryptor()
{
return this.CreateEncryptor(this.Key, this.IV);
}
/// <summary>When overridden in a derived class, creates a symmetric encryptor object with the specified <see cref="P:System.Security.Cryptography.SymmetricAlgorithm.Key" /> property and initialization vector (<see cref="P:System.Security.Cryptography.SymmetricAlgorithm.IV" />).</summary>
/// <returns>A symmetric encryptor object.</returns>
/// <param name="rgbKey">The secret key to use for the symmetric algorithm. </param>
/// <param name="rgbIV">The initialization vector to use for the symmetric algorithm. </param>
// Token: 0x060030F6 RID: 12534
public abstract ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[] rgbIV);
/// <summary>When overridden in a derived class, generates a random initialization vector (<see cref="P:System.Security.Cryptography.SymmetricAlgorithm.IV" />) to use for the algorithm.</summary>
// Token: 0x060030F7 RID: 12535
public abstract void GenerateIV();
/// <summary>When overridden in a derived class, generates a random key (<see cref="P:System.Security.Cryptography.SymmetricAlgorithm.Key" />) to use for the algorithm.</summary>
// Token: 0x060030F8 RID: 12536
public abstract void GenerateKey();
/// <summary>Determines whether the specified key size is valid for the current algorithm.</summary>
/// <returns>true if the specified key size is valid for the current algorithm; otherwise, false.</returns>
/// <param name="bitLength">The length, in bits, to check for a valid key size. </param>
// Token: 0x060030F9 RID: 12537 RVA: 0x000A8408 File Offset: 0x000A6608
public bool ValidKeySize(int bitLength)
{
return KeySizes.IsLegalKeySize(this.LegalKeySizesValue, bitLength);
}
/// <summary>Creates a default cryptographic object used to perform the symmetric algorithm.</summary>
/// <returns>A default cryptographic object used to perform the symmetric algorithm.</returns>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" />
/// </PermissionSet>
// Token: 0x060030FA RID: 12538 RVA: 0x000A8418 File Offset: 0x000A6618
public static SymmetricAlgorithm Create()
{
return SymmetricAlgorithm.Create("System.Security.Cryptography.SymmetricAlgorithm");
}
/// <summary>Creates the specified cryptographic object used to perform the symmetric algorithm.</summary>
/// <returns>A cryptographic object used to perform the symmetric algorithm.</returns>
/// <param name="algName">The name of the specific implementation of the <see cref="T:System.Security.Cryptography.SymmetricAlgorithm" /> class to use. </param>
// Token: 0x060030FB RID: 12539 RVA: 0x000A8424 File Offset: 0x000A6624
public static SymmetricAlgorithm Create(string algName)
{
return (SymmetricAlgorithm)CryptoConfig.CreateFromName(algName);
}
/// <summary>Represents the block size, in bits, of the cryptographic operation.</summary>
// Token: 0x040013F9 RID: 5113
protected int BlockSizeValue;
/// <summary>Represents the initialization vector (<see cref="P:System.Security.Cryptography.SymmetricAlgorithm.IV" />) for the symmetric algorithm.</summary>
// Token: 0x040013FA RID: 5114
protected byte[] IVValue;
/// <summary>Represents the size, in bits, of the secret key used by the symmetric algorithm.</summary>
// Token: 0x040013FB RID: 5115
protected int KeySizeValue;
/// <summary>Represents the secret key for the symmetric algorithm.</summary>
// Token: 0x040013FC RID: 5116
protected byte[] KeyValue;
/// <summary>Specifies the block sizes, in bits, that are supported by the symmetric algorithm.</summary>
// Token: 0x040013FD RID: 5117
protected KeySizes[] LegalBlockSizesValue;
/// <summary>Specifies the key sizes, in bits, that are supported by the symmetric algorithm.</summary>
// Token: 0x040013FE RID: 5118
protected KeySizes[] LegalKeySizesValue;
/// <summary>Represents the feedback size, in bits, of the cryptographic operation.</summary>
// Token: 0x040013FF RID: 5119
protected int FeedbackSizeValue;
/// <summary>Represents the cipher mode used in the symmetric algorithm.</summary>
// Token: 0x04001400 RID: 5120
protected CipherMode ModeValue;
/// <summary>Represents the padding mode used in the symmetric algorithm.</summary>
// Token: 0x04001401 RID: 5121
protected PaddingMode PaddingValue;
// Token: 0x04001402 RID: 5122
private bool m_disposed;
}
}