mirror of
https://github.com/BepInEx/mono.git
synced 2026-11-19 01:31:17 -10:00
* HashAlgorithm.cs: Added Dispose() to HashAlgorithm because it inherits ICryptoTransform * KeyedHashAlgorithm.cs: New implementation * HMACSHA1.cs: New (include a generic HMACAlgorithm as internal class) * MACTripleDES.cs: New (missing core implementation on generic MACAlgorithm) * CryptoStream.cs: Added limited functionalities to support HMACSHA1 svn path=/trunk/mcs/; revision=8221
73 lines
1.5 KiB
C#
73 lines
1.5 KiB
C#
//
|
|
// KeyedHashAlgorithm.cs: Handles keyed hash and MAC classes.
|
|
//
|
|
// Author:
|
|
// Sebastien Pouliot ([email protected])
|
|
//
|
|
// (C) 2002 Motus Technologies Inc. (http://www.motus.com)
|
|
//
|
|
|
|
using System;
|
|
using System.Security.Cryptography;
|
|
|
|
namespace System.Security.Cryptography {
|
|
|
|
public abstract class KeyedHashAlgorithm : HashAlgorithm {
|
|
|
|
protected byte[] KeyValue;
|
|
|
|
protected KeyedHashAlgorithm () : base ()
|
|
{
|
|
// create a random 64 bits key
|
|
}
|
|
|
|
~KeyedHashAlgorithm ()
|
|
{
|
|
Dispose (false);
|
|
}
|
|
|
|
public virtual byte[] Key {
|
|
get {
|
|
return (byte[]) KeyValue.Clone ();
|
|
}
|
|
set {
|
|
// can't change the key during a hashing ops
|
|
if (State != 0)
|
|
throw new CryptographicException ();
|
|
// zeroize current key material for security
|
|
ZeroizeKey ();
|
|
// copy new key
|
|
KeyValue = (byte[]) value.Clone ();
|
|
}
|
|
}
|
|
|
|
protected override void Dispose (bool disposing)
|
|
{
|
|
// zeroize key material for security
|
|
ZeroizeKey();
|
|
// dispose managed resources
|
|
// none so far
|
|
// dispose unmanaged resources
|
|
// none so far
|
|
// calling base class HashAlgorithm
|
|
base.Dispose (disposing);
|
|
}
|
|
|
|
private void ZeroizeKey()
|
|
{
|
|
if (KeyValue != null)
|
|
Array.Clear (KeyValue, 0, KeyValue.Length);
|
|
}
|
|
|
|
public static new KeyedHashAlgorithm Create ()
|
|
{
|
|
return Create ("System.Security.Cryptography.KeyedHashAlgorithm");
|
|
}
|
|
|
|
public static new KeyedHashAlgorithm Create (string algName)
|
|
{
|
|
return (KeyedHashAlgorithm) CryptoConfig.CreateFromName (algName);
|
|
}
|
|
}
|
|
|
|
} |