-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
61 lines (53 loc) · 2.09 KB
/
Program.cs
File metadata and controls
61 lines (53 loc) · 2.09 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
using Newtonsoft.Json;
using OtpNet;
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace HelloWorld
{
public class Item
{
public string name = "";
public string code = "";
// public DateTime datetime;
}
class Program
{
static void Main(string[] args)
{
// Random hash
var key = KeyGeneration.GenerateRandomKey(20);
var base32String = Base32Encoding.ToString(key);
Console.WriteLine("-------------------------------------");
Console.WriteLine("Random {0}", base32String);
Console.WriteLine("-------------------------------------");
// using StreamReader r = new(@"D:\Git\file.json");
// From JSON
using StreamReader r = new(@"secrets\secrets.json");
string? json = r.ReadToEnd();
if (json != null)
{
List<Item>? items = JsonConvert.DeserializeObject<List<Item>>(json);
while (true)
{
dynamic? array = JsonConvert.DeserializeObject(json) ?? new List<Object>();
foreach (var item in array)
{
string itemName = item.name;
string itemCode = item.code;
var otpCode = new Totp(Base32Encoding.ToBytes(itemCode)).ComputeTotp(DateTime.UtcNow);
Console.WriteLine("{0}", DateTime.UtcNow.ToString());
Console.WriteLine("===> {0}", itemName);
Console.WriteLine("======> {0}", otpCode);
Console.WriteLine("----------------------------------------");
}
Thread.Sleep(15000); // 30 second delay
Console.Clear();
}
}
Console.WriteLine("\nPress any key to exit.");
Console.ReadKey();
}
}
}