Statistics
| Branch: | Revision:

root / trunk / hammock / src / netCF / Hammock.Compact / Security / Cryptography / KeyedHashAlgorithm.cs @ 0eea575a

History | View | Annotate | Download (1.1 kB)

1
using System;
2
using System.Security.Cryptography;
3

    
4
namespace Hammock.Security.Cryptography
5
{
6
  public abstract class KeyedHashAlgorithm : HashAlgorithm
7
  {
8
    protected byte[] KeyValue;
9

    
10
    public virtual byte[] Key
11
    {
12
      get
13
      {
14
        return (byte[])this.KeyValue.Clone();
15
      }
16
      set
17
      {
18
        if (this.State != 0)
19
        {
20
          throw new CryptographicException("Key can't be changed at this state.");
21
        }
22

    
23
        this.ZeroizeKey();
24
        this.KeyValue = (byte[])value.Clone();
25
      }
26
    }
27

    
28
    ~KeyedHashAlgorithm()
29
    {
30
      this.Dispose(false);
31
    }
32

    
33
    protected override void Dispose(bool disposing)
34
    {
35
      this.ZeroizeKey();
36
      base.Dispose(disposing);
37
    }
38

    
39
    private void ZeroizeKey()
40
    {
41
      if (this.KeyValue != null)
42
        Array.Clear(this.KeyValue, 0, this.KeyValue.Length);
43
    }
44

    
45
    public static new KeyedHashAlgorithm Create()
46
    {
47
      return Create("System.Security.Cryptography.KeyedHashAlgorithm");
48
    }
49

    
50
    public static new KeyedHashAlgorithm Create(string algName)
51
    {
52
      return (KeyedHashAlgorithm)CryptoConfig.CreateFromName(algName);
53
    }
54
  }
55
}