2 using System.Security.Cryptography;
3 using Hammock.Mono.Security.Cryptography;
5 namespace Hammock.Security.Cryptography
7 public class HMACSHA1 : KeyedHashAlgorithm
9 private readonly HMACAlgorithm hmac;
10 private bool m_disposed;
12 public override sealed byte[] Key
20 this.hmac.Key = value;
25 public string HashName
29 return this.hmac.HashName;
34 this.hmac.HashName = value;
39 : this(KeyBuilder.Key(8))
43 public HMACSHA1(byte[] rgbKey)
45 this.hmac = new HMACAlgorithm("SHA1");
46 this.HashSizeValue = 160;
48 this.m_disposed = false;
56 protected override void Dispose(bool disposing)
60 if (this.hmac != null)
62 base.Dispose(disposing);
63 this.m_disposed = true;
67 public override void Initialize()
70 throw new ObjectDisposedException("HMACSHA1");
71 else if (!(this.hmac.Algo is SHA1))
73 throw new InvalidCastException(string.Format("Invalid hash algorithm '{0}', expected '{1}'.", this.hmac.Algo == null ? (object)"none" : (object)this.hmac.Algo.GetType().ToString(), (object)"SHA1"));
78 this.hmac.Initialize();
82 protected override void HashCore(byte[] rgb, int ib, int cb)
86 throw new ObjectDisposedException("HMACSHA1");
95 this.hmac.Core(rgb, ib, cb);
99 protected override byte[] HashFinal()
103 throw new ObjectDisposedException("HMACSHA1");
108 return this.hmac.Final();