-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
68 lines (63 loc) · 2.15 KB
/
Program.cs
File metadata and controls
68 lines (63 loc) · 2.15 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* This sample demonstrates securely hashing a student ID into an alternate
* student ID that is suitable for de-identified test results. It uses the
* HMAC-SHA1 keyed-hash algorithm. The technique is appropriate for other
* digital signature applications.
*
* Written by Brandt Redd
* Released under a Creative Commons CC0 Dedication
* http://creativecommons.org/publicdomain/zero/1.0/
* To the extent possible under law, Brandt Redd has waived all copyright
* and related or neighboring rights to Hash Student ID Sample. This work
* is published from: United States
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
namespace HashStudentIDSample
{
class Program
{
static void Main(string[] args)
{
if (args.Length != 2 || string.Equals(args[0], "-h", StringComparison.OrdinalIgnoreCase))
{
Console.WriteLine("Syntax: HashStudentIdSample <studentId> <hashKeyPassPhrase>");
}
else
{
Console.WriteLine("Alternate student ID is:");
StudentIdHasher hasher = new StudentIdHasher(args[1]);
Console.WriteLine(hasher.HashStudentId(args[0]));
}
// If running outside of a command-line shell, let the user see the output before closing.
if (ConsoleHelper.IsSoleConsoleOwner)
{
Console.WriteLine();
Console.Write("Press any key to exit.");
Console.ReadKey();
}
}
}
static class ConsoleHelper
{
[DllImport("kernel32.dll", SetLastError = true)]
private static extern uint GetConsoleProcessList(
uint[] ProcessList,
uint ProcessCount
);
public static bool IsSoleConsoleOwner
{
get
{
uint[] procIds = new uint[4];
uint count = GetConsoleProcessList(procIds, (uint)procIds.Length);
return count <= 1;
}
}
}
}