Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
HashedAuthenticationMechanism.cs
1using System;
2
4{
9 {
14 {
15 }
16
22 public abstract byte[] H(byte[] Data);
23
29 public virtual byte[] H(string s)
30 {
31 return this.H(System.Text.Encoding.UTF8.GetBytes(s));
32 }
33
41 protected byte[] HMAC(byte[] Key, byte[] Text)
42 {
43 byte[] A1 = Key;
44 if (A1.Length > 64)
45 A1 = this.H(A1);
46
47 if (A1.Length < 64)
48 Array.Resize(ref A1, 64);
49
50 byte[] A3 = (byte[])A1.Clone();
51 int i;
52
53 for (i = 0; i < 64; i++)
54 {
55 A1[i] ^= 0x5c; // opad
56 A3[i] ^= 0x36; // ipad
57 }
58
59 return this.H(CONCAT(A1, this.H(CONCAT(A3, Text))));
60 }
61
68 protected byte[] KD(string k, string s)
69 {
70 return this.H(CONCAT(k, ":", s));
71 }
72 }
73}
Base class for all authentication mechanisms.
static byte[] CONCAT(params byte[][] Data)
Concatenates a sequence of byte arrays.
Base class for all hashed authentication mechanisms.
HashedAuthenticationMechanism()
Base class for all hashed authentication mechanisms.
abstract byte[] H(byte[] Data)
Hash function
byte[] HMAC(byte[] Key, byte[] Text)
See RFC 2104 for a description of the HMAC algorithm: http://tools.ietf.org/html/rfc2104