aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Core/Cryptography
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/Tango.Core/Cryptography')
-rw-r--r--Software/Visual_Studio/Tango.Core/Cryptography/MachineLevelCryptographer.cs40
-rw-r--r--Software/Visual_Studio/Tango.Core/Cryptography/PasswordGenerator.cs79
2 files changed, 0 insertions, 119 deletions
diff --git a/Software/Visual_Studio/Tango.Core/Cryptography/MachineLevelCryptographer.cs b/Software/Visual_Studio/Tango.Core/Cryptography/MachineLevelCryptographer.cs
deleted file mode 100644
index 04fd036a4..000000000
--- a/Software/Visual_Studio/Tango.Core/Cryptography/MachineLevelCryptographer.cs
+++ /dev/null
@@ -1,40 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Security.Cryptography;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace Tango.Core.Cryptography
-{
- public class MachineLevelCryptographer : ICryptographer
- {
- public string Encrypt(string text)
- {
- return Encrypt(text, "Twine1357");
- }
-
- public string Encrypt(string text, string key)
- {
- return Convert.ToBase64String(
- ProtectedData.Protect(
- Encoding.UTF8.GetBytes(text)
- , key != null ? Encoding.UTF8.GetBytes(key) : null
- , DataProtectionScope.LocalMachine));
- }
-
- public string Decrypt(string text)
- {
- return Decrypt(text, "Twine1357");
- }
-
- public string Decrypt(string text, string key)
- {
- return Encoding.UTF8.GetString(
- ProtectedData.Unprotect(
- Convert.FromBase64String(text)
- , key != null ? Encoding.UTF8.GetBytes(key) : null
- , DataProtectionScope.LocalMachine));
- }
- }
-}
diff --git a/Software/Visual_Studio/Tango.Core/Cryptography/PasswordGenerator.cs b/Software/Visual_Studio/Tango.Core/Cryptography/PasswordGenerator.cs
deleted file mode 100644
index 50f59b744..000000000
--- a/Software/Visual_Studio/Tango.Core/Cryptography/PasswordGenerator.cs
+++ /dev/null
@@ -1,79 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Security.Cryptography;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace Tango.Core.Cryptography
-{
- public static class PasswordGenerator
- {
- internal static readonly String alphaNumeric = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
- internal static readonly String numeric = "1234567890";
- internal static readonly String alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
-
- public enum PasswordType
- {
- Alphaumeric,
- Numeric,
- Alpha,
- }
-
- public enum PasswordCasing
- {
- Any,
- Upper,
- Lower
- }
-
- public static String Generate(int length, PasswordType type = PasswordType.Alphaumeric, PasswordCasing casing = PasswordCasing.Any)
- {
- String chars = String.Empty;
-
- switch (type)
- {
- case PasswordType.Alphaumeric:
- chars = alphaNumeric;
- break;
- case PasswordType.Numeric:
- chars = numeric;
- break;
- case PasswordType.Alpha:
- chars = alpha;
- break;
- }
-
- switch (casing)
- {
- case PasswordCasing.Upper:
- chars = chars.ToUpper();
- break;
- case PasswordCasing.Lower:
- chars = chars.ToLower();
- break;
- }
-
- return GetUniqueKey(chars.ToCharArray(), length);
- }
-
- private static string GetUniqueKey(char[] chars, int size)
- {
- byte[] data = new byte[4 * size];
- using (RNGCryptoServiceProvider crypto = new RNGCryptoServiceProvider())
- {
- crypto.GetBytes(data);
- }
- StringBuilder result = new StringBuilder(size);
- for (int i = 0; i < size; i++)
- {
- var rnd = BitConverter.ToUInt32(data, i * 4);
- var idx = rnd % chars.Length;
-
- result.Append(chars[idx]);
- }
-
- return result.ToString();
- }
- }
-}