-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
KeyChecksum.cs
49 lines (43 loc) · 1.36 KB
/
KeyChecksum.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
namespace Leosac.KeyManager.Library
{
public abstract class KeyChecksum
{
public abstract string Name { get; }
public string ComputeKCV(string tag, string key)
{
return ComputeKCV(tag, key, null);
}
public string ComputeKCV(string tag, string key, string? iv)
{
return ComputeKCV(new[] { tag }, key, iv);
}
public string ComputeKCV(IEnumerable<string> tags, string key)
{
return ComputeKCV(tags, key, null);
}
public string ComputeKCV(IEnumerable<string> tags, string key, string? iv)
{
byte[]? ivb = null;
if (!string.IsNullOrEmpty(iv))
{
ivb = Convert.FromHexString(iv);
}
uint keySize = 0;
if (!string.IsNullOrEmpty(key))
{
keySize = (uint)key.Length / 2;
}
return Convert.ToHexString(ComputeKCV(new Key(tags, keySize, key), ivb));
}
public string ComputeKCV(Key key, string? iv)
{
byte[]? ivb = null;
if (!string.IsNullOrEmpty(iv))
{
ivb = Convert.FromHexString(iv);
}
return Convert.ToHexString(ComputeKCV(key, ivb));
}
public abstract byte[] ComputeKCV(Key key, byte[]? iv);
}
}