Skip to content

Commit 8cf8914

Browse files
committed
first commit
0 parents  commit 8cf8914

File tree

277 files changed

+1781
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

277 files changed

+1781
-0
lines changed

.vscode/launch.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
// Use IntelliSense to find out which attributes exist for C# debugging
6+
// Use hover for the description of the existing attributes
7+
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
8+
"name": ".NET Core Launch (console)",
9+
"type": "coreclr",
10+
"request": "launch",
11+
"preLaunchTask": "build",
12+
// If you have changed target frameworks, make sure to update the program path.
13+
"program": "${workspaceFolder}/bin/Debug/net6.0/encryptStringWin64.dll",
14+
"args": [],
15+
"cwd": "${workspaceFolder}",
16+
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
17+
"console": "internalConsole",
18+
"stopAtEntry": false
19+
},
20+
{
21+
"name": ".NET Core Attach",
22+
"type": "coreclr",
23+
"request": "attach"
24+
}
25+
]
26+
}

.vscode/tasks.json

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "build",
6+
"command": "dotnet",
7+
"type": "process",
8+
"args": [
9+
"build",
10+
"${workspaceFolder}/encryptStringWin64.csproj",
11+
"/property:GenerateFullPaths=true",
12+
"/consoleloggerparameters:NoSummary"
13+
],
14+
"problemMatcher": "$msCompile"
15+
},
16+
{
17+
"label": "publish",
18+
"command": "dotnet",
19+
"type": "process",
20+
"args": [
21+
"publish",
22+
"${workspaceFolder}/encryptStringWin64.csproj",
23+
"/property:GenerateFullPaths=true",
24+
"/consoleloggerparameters:NoSummary"
25+
],
26+
"problemMatcher": "$msCompile"
27+
},
28+
{
29+
"label": "watch",
30+
"command": "dotnet",
31+
"type": "process",
32+
"args": [
33+
"watch",
34+
"run",
35+
"--project",
36+
"${workspaceFolder}/encryptStringWin64.csproj"
37+
],
38+
"problemMatcher": "$msCompile"
39+
}
40+
]
41+
}

Program.cs

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
using System;
2+
using System.IO;
3+
using System.Text;
4+
using System.Security.Cryptography;
5+
6+
namespace encryptString
7+
{
8+
class Program
9+
{
10+
// Reading in any commandline parameters at startup
11+
12+
static void Main(string[] args)
13+
{
14+
15+
// Checking to see if any command line parameters were added to the commmand,
16+
// if not printing out instructions
17+
18+
if (args.Length == 0)
19+
{
20+
Console.WriteLine("\nInvalid Parameters\n");
21+
Console.WriteLine("Encrypt Useage: encryptString encrypt -s {0}stringValue{0}", Convert.ToChar(34));
22+
Console.WriteLine("Decrypt Useage: encryptString decrypt -s {0}stringValue{0}", Convert.ToChar(34));
23+
Console.WriteLine("\n");
24+
return;
25+
}
26+
27+
var key = "C498FD371940D49710867BE27345D3B9"; // Setting the encryption key for the program
28+
var content = ""; // Declaring a variable to store the incoming text
29+
var encrypted = ""; // Declaring a variable for encrypted text
30+
var decrypted = ""; // Declaring a variable for decrypted text
31+
var command = args[0]; // Storing commandline paramters in an arrary to process
32+
33+
// Switch statement to process the commands
34+
35+
switch (command)
36+
{
37+
// if the encrypt parameter was defined, then do this...
38+
case "encrypt" when args.Length == 3 && args[1] == "-s":
39+
content = args[2];
40+
encrypted = EncryptString(content, key);
41+
Console.WriteLine("\nEncrypted String: " + encrypted + "\n");
42+
break;
43+
44+
// if the decrypt parameter was defined, then do this...
45+
case "decrypt" when args.Length == 3 && args[1] == "-s":
46+
encrypted = args[2];
47+
decrypted = DecryptString(encrypted, key);
48+
Console.WriteLine("\nDecrypted String: " + decrypted + "\n");
49+
break;
50+
51+
// if the commands don't make any sense then print out the instructions again
52+
default:
53+
Console.WriteLine("\nInvalid Parameters\n");
54+
Console.WriteLine("Encrypt Useage: encryptString encrypt -s {0}stringValue{0}", Convert.ToChar(34));
55+
Console.WriteLine("Decrypt Useage: encryptString decrypt -s {0}stringValue{0}", Convert.ToChar(34));
56+
Console.WriteLine("\n");
57+
break;
58+
}
59+
60+
System.Environment.Exit(0);
61+
}
62+
63+
// Function to encrypt the string for storage
64+
65+
public static string EncryptString(string text, string keyString)
66+
{
67+
var key = Encoding.UTF8.GetBytes(keyString);
68+
using (var aesAlg = Aes.Create())
69+
{
70+
using (var encryptor = aesAlg.CreateEncryptor(key, aesAlg.IV))
71+
{
72+
using (var msEncrypt = new MemoryStream())
73+
{
74+
using (var csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
75+
using (var swEncrypt = new StreamWriter(csEncrypt))
76+
{
77+
swEncrypt.Write(text);
78+
}
79+
80+
var iv = aesAlg.IV;
81+
82+
var decryptedContent = msEncrypt.ToArray();
83+
84+
var result = new byte[iv.Length + decryptedContent.Length];
85+
86+
Buffer.BlockCopy(iv, 0, result, 0, iv.Length);
87+
Buffer.BlockCopy(decryptedContent, 0, result, iv.Length, decryptedContent.Length);
88+
89+
return Convert.ToBase64String(result);
90+
}
91+
}
92+
}
93+
}
94+
95+
// Function decrypt the string for storage
96+
97+
public static string DecryptString(string cipherText, string keyString)
98+
{
99+
var fullCipher = Convert.FromBase64String(cipherText);
100+
101+
var iv = new byte[16];
102+
var cipher = new byte[16];
103+
104+
Buffer.BlockCopy(fullCipher, 0, iv, 0, iv.Length);
105+
Buffer.BlockCopy(fullCipher, iv.Length, cipher, 0, iv.Length);
106+
var key = Encoding.UTF8.GetBytes(keyString);
107+
108+
using (var aesAlg = Aes.Create())
109+
{
110+
using (var decryptor = aesAlg.CreateDecryptor(key, iv))
111+
{
112+
string result;
113+
using (var msDecrypt = new MemoryStream(cipher))
114+
{
115+
using (var csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
116+
{
117+
using (var srDecrypt = new StreamReader(csDecrypt))
118+
{
119+
result = srDecrypt.ReadToEnd();
120+
}
121+
}
122+
}
123+
124+
return result;
125+
}
126+
}
127+
}
128+
}
129+
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
15.1 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
23.6 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
25.1 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
20.6 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
15.6 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
525 KB
Binary file not shown.
170 KB
Binary file not shown.
Binary file not shown.
1.72 MB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
77.1 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
17.6 KB
Binary file not shown.
Binary file not shown.
15.6 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
41.6 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
18.1 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
15.6 KB
Binary file not shown.
16.1 KB
Binary file not shown.
16.1 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
24.1 KB
Binary file not shown.
49.6 KB
Binary file not shown.
16.6 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
298 KB
Binary file not shown.
1.37 MB
Binary file not shown.
4.89 MB
Binary file not shown.
56.2 KB
Binary file not shown.
137 KB
Binary file not shown.

0 commit comments

Comments
 (0)