mirror of
https://github.com/BepInEx/mono.git
synced 2026-11-18 17:02:10 -10:00
* HashAlgorithm.cs: Moved XML comments to monodoc. Added globalization to exceptions. * KeyedHashAlgorithm.cs: Added globalization to exceptions. * KeySizes.cs: Moved XML comments to monodoc. * MaskGenerationMethod.cs: Source clean up. * MD5.cs: Moved XML comments to monodoc. * MD5CryptoServiceProvider.cs: Removed CLSCompliance attributes from private fields. Changed constants from enum to array. Zeroize data on Dispose. * PaddingMode.cs: Moved XML comments to monodoc. * PasswordDeriveBytes.cs: Added globalization to exceptions. Removed TODO and documented as "not supported" in MonoDoc. * RandomNumberGenerator.cs: Source clean up. svn path=/trunk/mcs/; revision=26773
77 lines
1.6 KiB
C#
77 lines
1.6 KiB
C#
//
|
|
// KeyedHashAlgorithm.cs: Handles keyed hash and MAC classes.
|
|
//
|
|
// Author:
|
|
// Sebastien Pouliot ([email protected])
|
|
//
|
|
// (C) 2002 Motus Technologies Inc. (http://www.motus.com)
|
|
// (C) 2004 Novell (http://www.novell.com)
|
|
//
|
|
|
|
using System;
|
|
using System.Globalization;
|
|
|
|
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 (
|
|
Locale.GetText ("Key can't be changed at this state."));
|
|
}
|
|
// 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);
|
|
}
|
|
}
|
|
|
|
}
|