215 lines
8.7 KiB
C#
215 lines
8.7 KiB
C#
using System;
|
|
using System.Runtime.InteropServices;
|
|
using Mono.Security.Cryptography;
|
|
|
|
namespace System.Security.Cryptography
|
|
{
|
|
/// <summary>Represents the abstract class from which all implementations of Hash-based Message Authentication Code (HMAC) must derive.</summary>
|
|
// Token: 0x02000501 RID: 1281
|
|
[ComVisible(true)]
|
|
public abstract class HMAC : KeyedHashAlgorithm
|
|
{
|
|
/// <summary>Initializes a new instance of the <see cref="T:System.Security.Cryptography.HMAC" /> class. </summary>
|
|
// Token: 0x06002F4D RID: 12109 RVA: 0x000987AC File Offset: 0x000969AC
|
|
protected HMAC()
|
|
{
|
|
this._disposed = false;
|
|
this._blockSizeValue = 64;
|
|
}
|
|
|
|
/// <summary>Gets or sets the block size to use in the hash value.</summary>
|
|
/// <returns>The block size to use in the hash value.</returns>
|
|
// Token: 0x17000957 RID: 2391
|
|
// (get) Token: 0x06002F4E RID: 12110 RVA: 0x000987C4 File Offset: 0x000969C4
|
|
// (set) Token: 0x06002F4F RID: 12111 RVA: 0x000987CC File Offset: 0x000969CC
|
|
protected int BlockSizeValue
|
|
{
|
|
get
|
|
{
|
|
return this._blockSizeValue;
|
|
}
|
|
set
|
|
{
|
|
this._blockSizeValue = value;
|
|
}
|
|
}
|
|
|
|
/// <summary>Gets or sets the name of the hash algorithm to use for hashing.</summary>
|
|
/// <returns>The name of the hash algorithm.</returns>
|
|
/// <exception cref="T:System.Security.Cryptography.CryptographicException">The current hash algorithm cannot be changed.</exception>
|
|
// Token: 0x17000958 RID: 2392
|
|
// (get) Token: 0x06002F50 RID: 12112 RVA: 0x000987D8 File Offset: 0x000969D8
|
|
// (set) Token: 0x06002F51 RID: 12113 RVA: 0x000987E0 File Offset: 0x000969E0
|
|
public string HashName
|
|
{
|
|
get
|
|
{
|
|
return this._hashName;
|
|
}
|
|
set
|
|
{
|
|
this._hashName = value;
|
|
this._algo = HashAlgorithm.Create(this._hashName);
|
|
}
|
|
}
|
|
|
|
/// <summary>Gets or sets the key to use in the hash algorithm.</summary>
|
|
/// <returns>The key to use in the hash algorithm.</returns>
|
|
/// <exception cref="T:System.Security.Cryptography.CryptographicException">An attempt is made to change the <see cref="P:System.Security.Cryptography.HMAC.Key" /> property after hashing has begun. </exception>
|
|
// Token: 0x17000959 RID: 2393
|
|
// (get) Token: 0x06002F52 RID: 12114 RVA: 0x000987FC File Offset: 0x000969FC
|
|
// (set) Token: 0x06002F53 RID: 12115 RVA: 0x00098810 File Offset: 0x00096A10
|
|
public override byte[] Key
|
|
{
|
|
get
|
|
{
|
|
return (byte[])base.Key.Clone();
|
|
}
|
|
set
|
|
{
|
|
if (value != null && value.Length > 64)
|
|
{
|
|
base.Key = this._algo.ComputeHash(value);
|
|
}
|
|
else
|
|
{
|
|
base.Key = (byte[])value.Clone();
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x1700095A RID: 2394
|
|
// (get) Token: 0x06002F54 RID: 12116 RVA: 0x00098858 File Offset: 0x00096A58
|
|
internal BlockProcessor Block
|
|
{
|
|
get
|
|
{
|
|
if (this._block == null)
|
|
{
|
|
this._block = new BlockProcessor(this._algo, this.BlockSizeValue >> 3);
|
|
}
|
|
return this._block;
|
|
}
|
|
}
|
|
|
|
// Token: 0x06002F55 RID: 12117 RVA: 0x00098890 File Offset: 0x00096A90
|
|
private byte[] KeySetup(byte[] key, byte padding)
|
|
{
|
|
byte[] array = new byte[this.BlockSizeValue];
|
|
for (int i = 0; i < key.Length; i++)
|
|
{
|
|
array[i] = key[i] ^ padding;
|
|
}
|
|
for (int j = key.Length; j < this.BlockSizeValue; j++)
|
|
{
|
|
array[j] = padding;
|
|
}
|
|
return array;
|
|
}
|
|
|
|
/// <summary>Releases the unmanaged resources used by the <see cref="T:System.Security.Cryptography.HMAC" /> class when a key change is legitimate 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: 0x06002F56 RID: 12118 RVA: 0x000988E4 File Offset: 0x00096AE4
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (!this._disposed)
|
|
{
|
|
base.Dispose(disposing);
|
|
}
|
|
}
|
|
|
|
/// <summary>When overridden in a derived class, routes data written to the object into the default <see cref="T:System.Security.Cryptography.HMAC" /> hash algorithm for computing the hash value.</summary>
|
|
/// <param name="rgb">The input data. </param>
|
|
/// <param name="ib">The offset into the byte array from which to begin using data. </param>
|
|
/// <param name="cb">The number of bytes in the array to use as data. </param>
|
|
// Token: 0x06002F57 RID: 12119 RVA: 0x000988F8 File Offset: 0x00096AF8
|
|
protected override void HashCore(byte[] rgb, int ib, int cb)
|
|
{
|
|
if (this._disposed)
|
|
{
|
|
throw new ObjectDisposedException("HMACSHA1");
|
|
}
|
|
if (this.State == 0)
|
|
{
|
|
this.Initialize();
|
|
this.State = 1;
|
|
}
|
|
this.Block.Core(rgb, ib, cb);
|
|
}
|
|
|
|
/// <summary>When overridden in a derived class, finalizes the hash computation after the last data is processed by the cryptographic stream object.</summary>
|
|
/// <returns>The computed hash code in a byte array.</returns>
|
|
// Token: 0x06002F58 RID: 12120 RVA: 0x00098944 File Offset: 0x00096B44
|
|
protected override byte[] HashFinal()
|
|
{
|
|
if (this._disposed)
|
|
{
|
|
throw new ObjectDisposedException("HMAC");
|
|
}
|
|
this.State = 0;
|
|
this.Block.Final();
|
|
byte[] hash = this._algo.Hash;
|
|
byte[] array = this.KeySetup(this.Key, 92);
|
|
this._algo.Initialize();
|
|
this._algo.TransformBlock(array, 0, array.Length, array, 0);
|
|
this._algo.TransformFinalBlock(hash, 0, hash.Length);
|
|
byte[] hash2 = this._algo.Hash;
|
|
this._algo.Initialize();
|
|
Array.Clear(array, 0, array.Length);
|
|
Array.Clear(hash, 0, hash.Length);
|
|
return hash2;
|
|
}
|
|
|
|
/// <summary>Initializes an instance of the default implementation of <see cref="T:System.Security.Cryptography.HMAC" />.</summary>
|
|
// Token: 0x06002F59 RID: 12121 RVA: 0x000989F0 File Offset: 0x00096BF0
|
|
public override void Initialize()
|
|
{
|
|
if (this._disposed)
|
|
{
|
|
throw new ObjectDisposedException("HMAC");
|
|
}
|
|
this.State = 0;
|
|
this.Block.Initialize();
|
|
byte[] array = this.KeySetup(this.Key, 54);
|
|
this._algo.Initialize();
|
|
this.Block.Core(array);
|
|
Array.Clear(array, 0, array.Length);
|
|
}
|
|
|
|
/// <summary>Creates an instance of the default implementation of a Hash-based Message Authentication Code (HMAC).</summary>
|
|
/// <returns>A new SHA-1 instance, unless the default settings have been changed by using the <cryptoClass> element.</returns>
|
|
/// <PermissionSet>
|
|
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" />
|
|
/// </PermissionSet>
|
|
// Token: 0x06002F5A RID: 12122 RVA: 0x00098A58 File Offset: 0x00096C58
|
|
public new static HMAC Create()
|
|
{
|
|
return HMAC.Create("System.Security.Cryptography.HMAC");
|
|
}
|
|
|
|
/// <summary>Creates an instance of the specified implementation of a Hash-based Message Authentication Code (HMAC).</summary>
|
|
/// <returns>A new instance of the specified HMAC implementation.</returns>
|
|
/// <param name="algorithmName">The HMAC implementation to use. The following table shows the valid values for the <paramref name="algorithmName" /> parameter and the algorithms they map to.Parameter valueImplements System.Security.Cryptography.HMAC<see cref="T:System.Security.Cryptography.HMACSHA1" />System.Security.Cryptography.KeyedHashAlgorithm<see cref="T:System.Security.Cryptography.HMACSHA1" />HMACMD5<see cref="T:System.Security.Cryptography.HMACMD5" />System.Security.Cryptography.HMACMD5<see cref="T:System.Security.Cryptography.HMACMD5" />HMACRIPEMD160<see cref="T:System.Security.Cryptography.HMACRIPEMD160" />System.Security.Cryptography.HMACRIPEMD160<see cref="T:System.Security.Cryptography. HMACRIPEMD160" />HMACSHA1<see cref="T:System.Security.Cryptography.HMACSHA1" />System.Security.Cryptography.HMACSHA1<see cref="T:System.Security.Cryptography. HMACSHA1" />HMACSHA256<see cref="T:System.Security.Cryptography.HMACSHA256" />System.Security.Cryptography.HMACSHA256<see cref="T:System.Security.Cryptography.HMACSHA256" />HMACSHA384<see cref="T:System.Security.Cryptography.HMACSHA384" />System.Security.Cryptography.HMACSHA384<see cref="T:System.Security.Cryptography.HMACSHA384" />HMACSHA512<see cref="T:System.Security.Cryptography.HMACSHA512" />System.Security.Cryptography.HMACSHA512<see cref="T:System.Security.Cryptography.HMACSHA512" />MACTripleDES<see cref="T:System.Security.Cryptography. MACTripleDES" />System.Security.Cryptography.MACTripleDES<see cref="T:System.Security.Cryptography.MACTripleDES" /></param>
|
|
// Token: 0x06002F5B RID: 12123 RVA: 0x00098A64 File Offset: 0x00096C64
|
|
public new static HMAC Create(string algorithmName)
|
|
{
|
|
return (HMAC)CryptoConfig.CreateFromName(algorithmName);
|
|
}
|
|
|
|
// Token: 0x04001351 RID: 4945
|
|
private bool _disposed;
|
|
|
|
// Token: 0x04001352 RID: 4946
|
|
private string _hashName;
|
|
|
|
// Token: 0x04001353 RID: 4947
|
|
private HashAlgorithm _algo;
|
|
|
|
// Token: 0x04001354 RID: 4948
|
|
private BlockProcessor _block;
|
|
|
|
// Token: 0x04001355 RID: 4949
|
|
private int _blockSizeValue;
|
|
}
|
|
}
|