Skip to content

Commit 8274dd0

Browse files
committed
Added bunch of tools
Mostly command line and need fixing for different drive letters
1 parent 9255f90 commit 8274dd0

File tree

11 files changed

+543
-0
lines changed

11 files changed

+543
-0
lines changed

utils/BatchHasher.cs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System;
2+
using System.Security.Cryptography;
3+
4+
namespace PBKDF2Hasher
5+
{
6+
public class BatchHasher
7+
{
8+
9+
public static byte[] generateSalt()
10+
{
11+
var csprng = new RNGCryptoServiceProvider();
12+
var salt = new byte[24];
13+
csprng.GetBytes(salt);
14+
return salt;
15+
}
16+
17+
public static int Main(string[] args)
18+
{
19+
if (args.Length == 0)
20+
{
21+
Console.WriteLine(@"Please give a word followed by a salt, seperated by a comma (with no spaces) to be hashed
22+
E.g beep,gxsnfYvKQIExdD233H8rpkx8MKp8KhdD - not beep, gxsnfYvKQIExdD233H8rpkx8MKp8KhdD");
23+
return 1;
24+
}
25+
byte[] salt = new byte[24];
26+
var SplitArgs = new string[args.Length][];
27+
for (int i = 0; i < args.Length; i++)
28+
{
29+
SplitArgs[i] = args[i].Split(',');
30+
if(SplitArgs[i].Length == 1)
31+
{
32+
Console.WriteLine("No salt detected - salt will be generated");
33+
salt = generateSalt();
34+
}
35+
}
36+
37+
var hashes = new byte[args.Length][];
38+
for (int i = 0; i < args.Length; i++)
39+
{
40+
byte[] hashValue;
41+
42+
43+
//Generate hash using salt
44+
using (var pbkdf2 = new Rfc2898DeriveBytes(SplitArgs[i][0], Convert.FromBase64String(SplitArgs[i][1]), 100000))
45+
{
46+
hashValue = pbkdf2.GetBytes(24);
47+
}
48+
hashes[i] = hashValue;
49+
}
50+
Console.WriteLine("Hashes come first, followed by a hiphen ('-') then the salt: ");
51+
for (int i = 0; i < args.Length; i++)
52+
{
53+
Console.WriteLine(Convert.ToBase64String(hashes[i]) + " - " + SplitArgs[i][1]);
54+
}
55+
56+
return 0;
57+
}
58+
}
59+
}

utils/Data.dat

230 Bytes
Binary file not shown.
5 KB
Binary file not shown.

utils/Executables/Hasher.exe

5 KB
Binary file not shown.

utils/Executables/HelloWorld.exe

3.5 KB
Binary file not shown.

utils/Executables/Protector.exe

5.5 KB
Binary file not shown.

utils/Hasher.cs

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
using System;
2+
using System.Security.Cryptography;
3+
4+
namespace PBKDF2Hasher
5+
{
6+
public class Hasher
7+
{
8+
9+
public static byte[] GenerateSalt()
10+
{
11+
var csprng = new RNGCryptoServiceProvider();
12+
var salt = new byte[32];
13+
csprng.GetBytes(salt);
14+
Console.WriteLine("Salt generated - {0}", Convert.ToBase64String(salt));
15+
return salt;
16+
}
17+
18+
public static int GetIterations()
19+
{
20+
Console.WriteLine("Please enter a number of iterations. If no input is given the program will default to 1 million: ");
21+
22+
int iterations;
23+
24+
string input = Console.ReadLine();
25+
if (input == "")
26+
{
27+
Console.WriteLine("Using default iterations");
28+
return 1000000;
29+
}
30+
try
31+
{
32+
iterations = Int32.Parse(input);
33+
}
34+
catch (FormatException)
35+
{
36+
Console.WriteLine("Please enter a valid number");
37+
return GetIterations();
38+
}
39+
return iterations;
40+
}
41+
42+
public static int Main(string[] args)
43+
{
44+
if (args.Length > 3 || args.Length == 0)
45+
{
46+
Console.WriteLine("Please give a word to be hashed, and optionally a salt and an iteration number");
47+
return 1;
48+
}
49+
50+
Byte[] salt;
51+
int iterations;
52+
53+
if (args.Length > 1)
54+
{
55+
salt = Convert.FromBase64String(args[1]);
56+
}
57+
else
58+
{
59+
salt = GenerateSalt();
60+
}
61+
62+
if (args.Length == 3)
63+
{
64+
iterations = Convert.ToInt32(args[3]);
65+
}
66+
else
67+
{
68+
iterations = GetIterations();
69+
70+
}
71+
72+
byte[] hashValue;
73+
74+
//Generate hash using salt
75+
using (var pbkdf2 = new Rfc2898DeriveBytes(args[0], salt, iterations))
76+
{
77+
Console.WriteLine("Hashing...");
78+
hashValue = pbkdf2.GetBytes(64);
79+
}
80+
81+
Console.WriteLine("\nHash: " + Convert.ToBase64String(hashValue) + "\n" + "Salt: " + Convert.ToBase64String(salt));
82+
83+
84+
return 0;
85+
}
86+
}
87+
}

utils/HelloWorld.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Diagnostics;
3+
4+
namespace App
5+
{
6+
class Application
7+
{
8+
public static void Main()
9+
{
10+
Console.WriteLine("Hello World!");
11+
Console.ReadKey();
12+
}
13+
}
14+
}

utils/Protector.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System;
2+
using System.IO;
3+
using System.Text;
4+
using System.Security.Cryptography;
5+
6+
namespace JLib.Security
7+
{
8+
public class DataProtector
9+
{
10+
public static void Main(string[] Args)
11+
{
12+
var data = Encoding.ASCII.GetBytes("MyData");
13+
var Length = ProtectDataToFile(data, @"C:\Users\johnk\Documents\General Code\C#\Data.dat", @"C:\Users\johnk\UNIENT\ent.dat");
14+
15+
var entropy = new byte[16];
16+
17+
using (var BinReader = new BinaryReader(File.Open(@"C:\Users\johnk\UNIENT\ent.dat", FileMode.Open)))
18+
{
19+
entropy = BinReader.ReadBytes(16);
20+
}
21+
Console.WriteLine(Encoding.ASCII.GetString(UnprotectDataFromFile(entropy, @"C:\Users\johnk\Documents\General Code\C#\Data.dat", Length)));
22+
}
23+
24+
public static long ProtectDataToFile(byte[] Data, string FilePath, string EntropyFilePath)
25+
{
26+
byte[] entropy = new byte[16];
27+
var rng = new RNGCryptoServiceProvider();
28+
rng.GetBytes(entropy);
29+
30+
var encryptedData = ProtectedData.Protect(Data, entropy, DataProtectionScope.CurrentUser);
31+
long Length = encryptedData.Length;
32+
33+
using (var BinWriter = new BinaryWriter(File.Open(EntropyFilePath, FileMode.Create)))
34+
{
35+
BinWriter.Write(entropy);
36+
}
37+
38+
using (var BinWriter = new BinaryWriter(File.Open(FilePath, FileMode.Create)))
39+
{
40+
BinWriter.Write(encryptedData);
41+
}
42+
43+
return Length;
44+
}
45+
46+
public static byte[] UnprotectDataFromFile(byte[] Entropy, string FilePath, long Length)
47+
{
48+
var data = new byte[Length];
49+
using (var BinReader = new BinaryReader(File.Open(FilePath, FileMode.Open)))
50+
{
51+
data = BinReader.ReadBytes((int)Length);
52+
}
53+
54+
return ProtectedData.Unprotect(data, Entropy, DataProtectionScope.CurrentUser);
55+
}
56+
}
57+
}

utils/Protector.exe

5 KB
Binary file not shown.

0 commit comments

Comments
 (0)