174 lines
6.3 KiB
C#
174 lines
6.3 KiB
C#
using System;
|
|
using System.Runtime.InteropServices;
|
|
using Mono.Security.Cryptography;
|
|
|
|
namespace System.Security.Cryptography
|
|
{
|
|
/// <summary>Computes a Message Authentication Code (MAC) using <see cref="T:System.Security.Cryptography.TripleDES" /> for the input data <see cref="T:System.Security.Cryptography.CryptoStream" />.</summary>
|
|
// Token: 0x0200050E RID: 1294
|
|
[ComVisible(true)]
|
|
public class MACTripleDES : KeyedHashAlgorithm
|
|
{
|
|
/// <summary>Initializes a new instance of the <see cref="T:System.Security.Cryptography.MACTripleDES" /> class.</summary>
|
|
// Token: 0x06002F9A RID: 12186 RVA: 0x000991BC File Offset: 0x000973BC
|
|
public MACTripleDES()
|
|
{
|
|
this.Setup("TripleDES", null);
|
|
}
|
|
|
|
/// <summary>Initializes a new instance of the <see cref="T:System.Security.Cryptography.MACTripleDES" /> class with the specified key data.</summary>
|
|
/// <param name="rgbKey">The secret key for <see cref="T:System.Security.Cryptography.MACTripleDES" /> encryption. </param>
|
|
/// <exception cref="T:System.ArgumentNullException">The <paramref name="rgbKey" /> parameter is null. </exception>
|
|
// Token: 0x06002F9B RID: 12187 RVA: 0x000991D0 File Offset: 0x000973D0
|
|
public MACTripleDES(byte[] rgbKey)
|
|
{
|
|
if (rgbKey == null)
|
|
{
|
|
throw new ArgumentNullException("rgbKey");
|
|
}
|
|
this.Setup("TripleDES", rgbKey);
|
|
}
|
|
|
|
/// <summary>Initializes a new instance of the <see cref="T:System.Security.Cryptography.MACTripleDES" /> class with the specified key data using the specified implementation of <see cref="T:System.Security.Cryptography.TripleDES" />.</summary>
|
|
/// <param name="strTripleDES">The name of the <see cref="T:System.Security.Cryptography.TripleDES" /> implementation to use. </param>
|
|
/// <param name="rgbKey">The secret key for <see cref="T:System.Security.Cryptography.MACTripleDES" /> encryption. </param>
|
|
/// <exception cref="T:System.ArgumentNullException">The <paramref name="rgbKey" /> parameter is null. </exception>
|
|
/// <exception cref="T:System.Security.Cryptography.CryptographicUnexpectedOperationException">The <paramref name="strTripleDES" /> parameter is not a valid name of a <see cref="T:System.Security.Cryptography.TripleDES" /> implementation. </exception>
|
|
// Token: 0x06002F9C RID: 12188 RVA: 0x000991F8 File Offset: 0x000973F8
|
|
public MACTripleDES(string strTripleDES, byte[] rgbKey)
|
|
{
|
|
if (rgbKey == null)
|
|
{
|
|
throw new ArgumentNullException("rgbKey");
|
|
}
|
|
if (strTripleDES == null)
|
|
{
|
|
this.Setup("TripleDES", rgbKey);
|
|
}
|
|
else
|
|
{
|
|
this.Setup(strTripleDES, rgbKey);
|
|
}
|
|
}
|
|
|
|
// Token: 0x06002F9D RID: 12189 RVA: 0x0009923C File Offset: 0x0009743C
|
|
private void Setup(string strTripleDES, byte[] rgbKey)
|
|
{
|
|
this.tdes = TripleDES.Create(strTripleDES);
|
|
this.tdes.Padding = PaddingMode.Zeros;
|
|
if (rgbKey != null)
|
|
{
|
|
this.tdes.Key = rgbKey;
|
|
}
|
|
this.HashSizeValue = this.tdes.BlockSize;
|
|
this.Key = this.tdes.Key;
|
|
this.mac = new MACAlgorithm(this.tdes);
|
|
this.m_disposed = false;
|
|
}
|
|
|
|
/// <summary>Releases the unmanaged resources used by the <see cref="T:System.Security.Cryptography.MACTripleDES" />.</summary>
|
|
// Token: 0x06002F9E RID: 12190 RVA: 0x000992B0 File Offset: 0x000974B0
|
|
~MACTripleDES()
|
|
{
|
|
this.Dispose(false);
|
|
}
|
|
|
|
/// <summary>Gets or sets the padding mode used in the hashing algorithm.</summary>
|
|
/// <returns>The padding mode used in the hashing algorithm.</returns>
|
|
/// <exception cref="T:System.Security.Cryptography.CryptographicException">The property cannot be set because the padding mode is invalid.</exception>
|
|
// Token: 0x1700096C RID: 2412
|
|
// (get) Token: 0x06002F9F RID: 12191 RVA: 0x000992EC File Offset: 0x000974EC
|
|
// (set) Token: 0x06002FA0 RID: 12192 RVA: 0x000992FC File Offset: 0x000974FC
|
|
[ComVisible(false)]
|
|
public PaddingMode Padding
|
|
{
|
|
get
|
|
{
|
|
return this.tdes.Padding;
|
|
}
|
|
set
|
|
{
|
|
this.tdes.Padding = value;
|
|
}
|
|
}
|
|
|
|
/// <summary>Releases the unmanaged resources used by the <see cref="T:System.Security.Cryptography.MACTripleDES" /> 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: 0x06002FA1 RID: 12193 RVA: 0x0009930C File Offset: 0x0009750C
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (!this.m_disposed)
|
|
{
|
|
if (this.KeyValue != null)
|
|
{
|
|
Array.Clear(this.KeyValue, 0, this.KeyValue.Length);
|
|
}
|
|
if (this.tdes != null)
|
|
{
|
|
this.tdes.Clear();
|
|
}
|
|
if (disposing)
|
|
{
|
|
this.KeyValue = null;
|
|
this.tdes = null;
|
|
}
|
|
base.Dispose(disposing);
|
|
this.m_disposed = true;
|
|
}
|
|
}
|
|
|
|
/// <summary>Initializes an instance of <see cref="T:System.Security.Cryptography.MACTripleDES" />.</summary>
|
|
// Token: 0x06002FA2 RID: 12194 RVA: 0x0009937C File Offset: 0x0009757C
|
|
public override void Initialize()
|
|
{
|
|
if (this.m_disposed)
|
|
{
|
|
throw new ObjectDisposedException("MACTripleDES");
|
|
}
|
|
this.State = 0;
|
|
this.mac.Initialize(this.KeyValue);
|
|
}
|
|
|
|
/// <summary>Routes data written to the object into the <see cref="T:System.Security.Cryptography.TripleDES" /> encryptor for computing the Message Authentication Code (MAC).</summary>
|
|
/// <param name="rgbData">The input data. </param>
|
|
/// <param name="ibStart">The offset into the byte array from which to begin using data. </param>
|
|
/// <param name="cbSize">The number of bytes in the array to use as data. </param>
|
|
// Token: 0x06002FA3 RID: 12195 RVA: 0x000993B8 File Offset: 0x000975B8
|
|
protected override void HashCore(byte[] rgbData, int ibStart, int cbSize)
|
|
{
|
|
if (this.m_disposed)
|
|
{
|
|
throw new ObjectDisposedException("MACTripleDES");
|
|
}
|
|
if (this.State == 0)
|
|
{
|
|
this.Initialize();
|
|
this.State = 1;
|
|
}
|
|
this.mac.Core(rgbData, ibStart, cbSize);
|
|
}
|
|
|
|
/// <summary>Returns the computed Message Authentication Code (MAC) after all data is written to the object.</summary>
|
|
/// <returns>The computed MAC.</returns>
|
|
// Token: 0x06002FA4 RID: 12196 RVA: 0x00099404 File Offset: 0x00097604
|
|
protected override byte[] HashFinal()
|
|
{
|
|
if (this.m_disposed)
|
|
{
|
|
throw new ObjectDisposedException("MACTripleDES");
|
|
}
|
|
this.State = 0;
|
|
return this.mac.Final();
|
|
}
|
|
|
|
// Token: 0x04001365 RID: 4965
|
|
private TripleDES tdes;
|
|
|
|
// Token: 0x04001366 RID: 4966
|
|
private MACAlgorithm mac;
|
|
|
|
// Token: 0x04001367 RID: 4967
|
|
private bool m_disposed;
|
|
}
|
|
}
|