diff --git a/DevsDaddy/Shared/CryptoLibrary/Core.meta b/DevsDaddy/Shared/CryptoLibrary/Core.meta
new file mode 100644
index 0000000..e370632
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Core.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: e79982a065cc4bc4943d1db4ba896ae3
+timeCreated: 1709889672
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Core/ICryptoProvider.cs b/DevsDaddy/Shared/CryptoLibrary/Core/ICryptoProvider.cs
new file mode 100644
index 0000000..c31101a
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Core/ICryptoProvider.cs
@@ -0,0 +1,36 @@
+namespace DevsDaddy.Shared.CryptoLibrary.Core
+{
+ ///
+ /// Base Crypto-Provider Interface
+ ///
+ public interface ICryptoProvider
+ {
+ ///
+ /// Decrypt String Data
+ ///
+ ///
+ ///
+ string DecryptString(string encryptedString);
+
+ ///
+ /// Decrypt Binary Data
+ ///
+ ///
+ ///
+ byte[] DecryptBinary(byte[] encryptedBinary);
+
+ ///
+ /// Encrypt String
+ ///
+ ///
+ ///
+ string EncryptString(string decryptedString);
+
+ ///
+ /// Encrypt Binary
+ ///
+ ///
+ ///
+ byte[] EncryptBinary(byte[] decryptedBinary);
+ }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Core/ICryptoProvider.cs.meta b/DevsDaddy/Shared/CryptoLibrary/Core/ICryptoProvider.cs.meta
new file mode 100644
index 0000000..5568ba4
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Core/ICryptoProvider.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: b2dfd16ad84e46dcb349978d4d7332c3
+timeCreated: 1709889459
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Core/IProviderOptions.cs b/DevsDaddy/Shared/CryptoLibrary/Core/IProviderOptions.cs
new file mode 100644
index 0000000..eac8100
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Core/IProviderOptions.cs
@@ -0,0 +1,7 @@
+namespace DevsDaddy.Shared.CryptoLibrary.Core
+{
+ ///
+ /// Provider Options Interface
+ ///
+ public interface IProviderOptions { }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Core/IProviderOptions.cs.meta b/DevsDaddy/Shared/CryptoLibrary/Core/IProviderOptions.cs.meta
new file mode 100644
index 0000000..34fd312
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Core/IProviderOptions.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 8334da39a9004bf5811d44dc29eaf43c
+timeCreated: 1709889484
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/CryptoController.cs b/DevsDaddy/Shared/CryptoLibrary/CryptoController.cs
new file mode 100644
index 0000000..c9730f5
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/CryptoController.cs
@@ -0,0 +1,72 @@
+using DevsDaddy.Shared.CryptoLibrary.Core;
+using DevsDaddy.Shared.CryptoLibrary.Modules.AES;
+
+namespace DevsDaddy.Shared.CryptoLibrary
+{
+ public static class CryptoController
+ {
+ // Default Provider
+ private static ICryptoProvider defaultProvider = new AESProvider();
+
+ ///
+ /// Set Default Crypto Provider
+ ///
+ ///
+ public static void SetDefaultProvider(ICryptoProvider provider) {
+ defaultProvider = provider;
+ }
+
+ ///
+ /// Decrypt Encrypted Plain-Text using provided Crypto-provider or Default Crypto-provider
+ ///
+ ///
+ ///
+ ///
+ public static string Decrypt(string encryptedString, ICryptoProvider provider = null) {
+ if (provider == null) provider = defaultProvider;
+ return provider.DecryptString(encryptedString);
+ }
+
+ ///
+ /// Decrypt encrypted byte array using provided Crypto-provider or Default Crypto-provider
+ ///
+ ///
+ ///
+ ///
+ public static byte[] Decrypt(byte[] encryptedArray, ICryptoProvider provider) {
+ if (provider == null) provider = defaultProvider;
+ return provider.DecryptBinary(encryptedArray);
+ }
+
+ ///
+ /// Encrypt plain-text using provided Crypto-provider or Default Crypto-provider
+ ///
+ ///
+ ///
+ ///
+ public static string Encrypt(string plainText, ICryptoProvider provider = null) {
+ if (provider == null) provider = defaultProvider;
+ return provider.EncryptString(plainText);
+ }
+
+ ///
+ /// Encrypt binary array using provided Crypto-provider or Default Crypto-provider
+ ///
+ ///
+ ///
+ ///
+ public static byte[] Encrypt(byte[] decryptedArray, ICryptoProvider provider = null) {
+ if (provider == null) provider = defaultProvider;
+ return provider.EncryptBinary(decryptedArray);
+ }
+
+ public static void Test() {
+ CryptoFile.SetDefaultProvider(new AESProvider(new AESEncryptionOptions {
+ cryptoKey = "key"
+ }));
+
+ string decryptedText = CryptoFile.ReadText("path_to_encrypted_file");
+ bool writtenFile = CryptoFile.WriteText("path_to_encrypted_file", decryptedText);
+ }
+ }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/CryptoController.cs.meta b/DevsDaddy/Shared/CryptoLibrary/CryptoController.cs.meta
new file mode 100644
index 0000000..7f46321
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/CryptoController.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 586014d07f2f4e3ab3881a37a1ee4e47
+timeCreated: 1709889696
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/CryptoFile.cs b/DevsDaddy/Shared/CryptoLibrary/CryptoFile.cs
new file mode 100644
index 0000000..d735d44
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/CryptoFile.cs
@@ -0,0 +1,180 @@
+using System;
+using System.IO;
+using System.Text;
+using System.Threading.Tasks;
+using DevsDaddy.Shared.CryptoLibrary.Core;
+using DevsDaddy.Shared.CryptoLibrary.Modules.AES;
+using UnityEngine;
+
+namespace DevsDaddy.Shared.CryptoLibrary
+{
+ public static class CryptoFile
+ {
+ // Default Provider
+ private static ICryptoProvider defaultProvider = new AESProvider();
+
+ ///
+ /// Set Default Crypto Provider
+ ///
+ ///
+ public static void SetDefaultProvider(ICryptoProvider provider) {
+ defaultProvider = provider;
+ }
+
+ ///
+ /// Write Text file to path with encrypted plain-text using provided / default crypto-provider
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static bool WriteText(string path, string plainText, ICryptoProvider provider = null) {
+ try {
+ if (provider == null) provider = defaultProvider;
+ string encryptedText = provider.EncryptString(plainText);
+ File.WriteAllText(path, encryptedText);
+ return true;
+ }
+ catch (Exception ex) {
+ Debug.LogError(ex);
+ return false;
+ }
+ }
+
+ ///
+ /// Write Binary File to path encrypted byte array using provided / default crypto-provider
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static bool WriteBinary(string path, byte[] byteArray, ICryptoProvider provider = null) {
+ try {
+ if (provider == null) provider = defaultProvider;
+ byte[] encryptedText = provider.EncryptBinary(byteArray);
+ File.WriteAllBytes(path, encryptedText);
+ return true;
+ }
+ catch (Exception ex) {
+ Debug.LogError(ex);
+ return false;
+ }
+ }
+
+ ///
+ /// Read encrypted file and returns decrypted plain-text using provided / default crypto-provider
+ ///
+ ///
+ ///
+ ///
+ public static async Task ReadTextAsync(string path, ICryptoProvider provider = null) {
+ try {
+ if (provider == null) provider = defaultProvider;
+ string encryptedText = await File.ReadAllTextAsync(path);
+ string decryptedText = provider.DecryptString(encryptedText);
+ return decryptedText;
+ }
+ catch (Exception ex) {
+ Debug.LogError(ex);
+ return null;
+ }
+ }
+
+ ///
+ /// Read encrypted binary file and returns decrypted byte array using provided / default crypto-provider
+ ///
+ ///
+ ///
+ ///
+ public static async Task ReadBinaryAsync(string path, ICryptoProvider provider = null) {
+ try {
+ if (provider == null) provider = defaultProvider;
+ byte[] encryptedData = await File.ReadAllBytesAsync(path);
+ byte[] decryptedData = provider.DecryptBinary(encryptedData);
+ return decryptedData;
+ }
+ catch (Exception ex) {
+ Debug.LogError(ex);
+ return null;
+ }
+ }
+
+ ///
+ /// Write Text file to path with encrypted plain-text using provided / default crypto-provider
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static async Task WriteTextAsync(string path, string plainText, ICryptoProvider provider = null) {
+ try {
+ if (provider == null) provider = defaultProvider;
+ string encryptedText = provider.EncryptString(plainText);
+ await File.WriteAllTextAsync(path, encryptedText);
+ return true;
+ }
+ catch (Exception ex) {
+ Debug.LogError(ex);
+ return false;
+ }
+ }
+
+ ///
+ /// Write Binary File to path encrypted byte array using provided / default crypto-provider
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static async Task WriteBinaryAsync(string path, byte[] byteArray, ICryptoProvider provider = null) {
+ try {
+ if (provider == null) provider = defaultProvider;
+ byte[] encryptedText = provider.EncryptBinary(byteArray);
+ await File.WriteAllBytesAsync(path, encryptedText);
+ return true;
+ }
+ catch (Exception ex) {
+ Debug.LogError(ex);
+ return false;
+ }
+ }
+
+ ///
+ /// Read encrypted file and returns decrypted plain-text using provided / default crypto-provider
+ ///
+ ///
+ ///
+ ///
+ public static string ReadText(string path, ICryptoProvider provider = null) {
+ try {
+ if (provider == null) provider = defaultProvider;
+ string encryptedText = File.ReadAllText(path);
+ string decryptedText = provider.DecryptString(encryptedText);
+ return decryptedText;
+ }
+ catch (Exception ex) {
+ Debug.LogError(ex);
+ return null;
+ }
+ }
+
+ ///
+ /// Read encrypted binary file and returns decrypted byte array using provided / default crypto-provider
+ ///
+ ///
+ ///
+ ///
+ public static byte[] ReadBinary(string path, ICryptoProvider provider = null) {
+ try {
+ if (provider == null) provider = defaultProvider;
+ byte[] encryptedData = File.ReadAllBytes(path);
+ byte[] decryptedData = provider.DecryptBinary(encryptedData);
+ return decryptedData;
+ }
+ catch (Exception ex) {
+ Debug.LogError(ex);
+ return null;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/CryptoFile.cs.meta b/DevsDaddy/Shared/CryptoLibrary/CryptoFile.cs.meta
new file mode 100644
index 0000000..5b9fcb5
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/CryptoFile.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 3b53aedd0664478da9df35f3cf683c18
+timeCreated: 1709889703
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/CryptoLibrary.asmdef b/DevsDaddy/Shared/CryptoLibrary/CryptoLibrary.asmdef
new file mode 100644
index 0000000..f41f8c8
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/CryptoLibrary.asmdef
@@ -0,0 +1,3 @@
+{
+ "name": "CryptoLibrary"
+}
diff --git a/DevsDaddy/Shared/CryptoLibrary/CryptoLibrary.asmdef.meta b/DevsDaddy/Shared/CryptoLibrary/CryptoLibrary.asmdef.meta
new file mode 100644
index 0000000..4f95962
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/CryptoLibrary.asmdef.meta
@@ -0,0 +1,7 @@
+fileFormatVersion: 2
+guid: 2576790177f6d514d97155b443dfc070
+AssemblyDefinitionImporter:
+ externalObjects: {}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/DevsDaddy/Shared/CryptoLibrary/CryptoModule.cs b/DevsDaddy/Shared/CryptoLibrary/CryptoModule.cs
new file mode 100644
index 0000000..fd05ca6
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/CryptoModule.cs
@@ -0,0 +1,7 @@
+namespace DevsDaddy.Shared.CryptoLibrary
+{
+ public enum CryptoModule
+ {
+
+ }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/CryptoModule.cs.meta b/DevsDaddy/Shared/CryptoLibrary/CryptoModule.cs.meta
new file mode 100644
index 0000000..0c15863
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/CryptoModule.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: b0c71a10e117439f93a15473c317dc03
+timeCreated: 1709889714
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules.meta b/DevsDaddy/Shared/CryptoLibrary/Modules.meta
new file mode 100644
index 0000000..ae9aef4
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: d1f1668f543df7e4eae8debf0d7dcfba
+folderAsset: yes
+DefaultImporter:
+ externalObjects: {}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/AES.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/AES.meta
new file mode 100644
index 0000000..d0b00b8
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/AES.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 2efc1c50b6ae4d659b53ee3428cc8c93
+timeCreated: 1709889626
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/AES/AESEncryptionOptions.cs b/DevsDaddy/Shared/CryptoLibrary/Modules/AES/AESEncryptionOptions.cs
new file mode 100644
index 0000000..11f8199
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/AES/AESEncryptionOptions.cs
@@ -0,0 +1,20 @@
+using System.Security.Cryptography;
+using System.Text;
+using DevsDaddy.Shared.CryptoLibrary.Core;
+
+namespace DevsDaddy.Shared.CryptoLibrary.Modules.AES
+{
+ [System.Serializable]
+ public class AESEncryptionOptions : IProviderOptions
+ {
+ public int bufferKeySize = 32;
+ public int blockSize = 256;
+ public int keySize = 256;
+
+ public string cryptoKey = "AESPassword";
+ public Encoding encoding = Encoding.UTF8;
+
+ public CipherMode cipherMode = CipherMode.CBC;
+ public PaddingMode paddingMode = PaddingMode.PKCS7;
+ }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/AES/AESEncryptionOptions.cs.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/AES/AESEncryptionOptions.cs.meta
new file mode 100644
index 0000000..4299bf0
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/AES/AESEncryptionOptions.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: a102000f019449dfaf93ff3b1485a75a
+timeCreated: 1709890300
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/AES/AESProvider.cs b/DevsDaddy/Shared/CryptoLibrary/Modules/AES/AESProvider.cs
new file mode 100644
index 0000000..ae10fba
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/AES/AESProvider.cs
@@ -0,0 +1,120 @@
+using System;
+using System.Collections.Generic;
+using System.Security.Cryptography;
+using DevsDaddy.Shared.CryptoLibrary.Core;
+
+namespace DevsDaddy.Shared.CryptoLibrary.Modules.AES
+{
+ ///
+ /// AES Encryption Provider.
+ /// Using for encrypt/decrypt plain text or byte arrays
+ ///
+ public class AESProvider : ICryptoProvider
+ {
+ private AESEncryptionOptions _options;
+
+ ///
+ /// AES Cryptography Provider
+ ///
+ ///
+ public AESProvider(AESEncryptionOptions options = null) {
+ _options = options ?? new AESEncryptionOptions();
+ }
+
+ ///
+ /// Decrypt AES-encrypted base-64 string to plain-text
+ ///
+ ///
+ ///
+ public string DecryptString(string encryptedString) {
+ byte[] decrypted = DecryptBinary(Convert.FromBase64String(encryptedString));
+ return _options.encoding.GetString(decrypted);
+ }
+
+ ///
+ /// Decrypt AES-encrypted binary
+ ///
+ ///
+ ///
+ public byte[] DecryptBinary(byte[] encryptedBinary) {
+ RijndaelManaged rij = setupRijndaelManaged;
+
+ List compile = new List(encryptedBinary);
+
+ // First 32 bytes are salt.
+ List salt = compile.GetRange(0, _options.bufferKeySize);
+ // Second 32 bytes are IV.
+ List iv = compile.GetRange(_options.bufferKeySize, _options.bufferKeySize);
+ rij.IV = iv.ToArray();
+
+ Rfc2898DeriveBytes deriveBytes = new Rfc2898DeriveBytes(_options.cryptoKey, salt.ToArray());
+ byte[] bufferKey = deriveBytes.GetBytes(_options.bufferKeySize); // Convert 32 bytes of salt to password
+ rij.Key = bufferKey;
+
+ byte[] plain = compile.GetRange(_options.bufferKeySize * 2, compile.Count - (_options.bufferKeySize * 2)).ToArray();
+
+ using (ICryptoTransform decrypt = rij.CreateDecryptor(rij.Key, rij.IV))
+ {
+ byte[] dest = decrypt.TransformFinalBlock(plain, 0, plain.Length);
+ return dest;
+ }
+ }
+
+ ///
+ /// Encrypt plain-text to AES-encrypted base-64 string
+ ///
+ ///
+ ///
+ public string EncryptString(string decryptedString) {
+ byte[] encrypted = EncryptBinary(_options.encoding.GetBytes(decryptedString));
+ return Convert.ToBase64String(encrypted);
+ }
+
+ ///
+ /// Encrypt byte array to AES-encrypted byte array
+ ///
+ ///
+ ///
+ public byte[] EncryptBinary(byte[] decryptedBinary) {
+ RijndaelManaged rij = setupRijndaelManaged;
+
+ // A pseudorandom number is newly generated based on the inputted password
+ Rfc2898DeriveBytes deriveBytes = new Rfc2898DeriveBytes(_options.cryptoKey, _options.bufferKeySize);
+ // The missing parts are specified in advance to fill in 0 length
+ byte[] salt = new byte[_options.bufferKeySize];
+ // Rfc2898DeriveBytes gets an internally generated salt
+ salt = deriveBytes.Salt;
+ // The 32-byte data extracted from the generated pseudorandom number is used as a password
+ byte[] bufferKey = deriveBytes.GetBytes(_options.bufferKeySize);
+
+ rij.Key = bufferKey;
+ rij.GenerateIV();
+
+ using (ICryptoTransform encrypt = rij.CreateEncryptor(rij.Key, rij.IV))
+ {
+ byte[] dest = encrypt.TransformFinalBlock(decryptedBinary, 0, decryptedBinary.Length);
+ // first 32 bytes of salt and second 32 bytes of IV for the first 64 bytes
+ List compile = new List(salt);
+ compile.AddRange(rij.IV);
+ compile.AddRange(dest);
+ return compile.ToArray();
+ }
+ }
+
+ ///
+ /// Setup Manager for AES
+ ///
+ private RijndaelManaged setupRijndaelManaged
+ {
+ get
+ {
+ RijndaelManaged rij = new RijndaelManaged();
+ rij.BlockSize = _options.blockSize;
+ rij.KeySize = _options.keySize;
+ rij.Mode = _options.cipherMode;
+ rij.Padding = _options.paddingMode;
+ return rij;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/AES/AESProvider.cs.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/AES/AESProvider.cs.meta
new file mode 100644
index 0000000..4f22a5d
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/AES/AESProvider.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 1f5f2cf3f4814af28f6d8b51353d90b6
+timeCreated: 1709889798
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/Base64.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/Base64.meta
new file mode 100644
index 0000000..a4f90af
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/Base64.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 6a9b5fa32f0f4013b1d98a5a89d4b7c7
+timeCreated: 1709889648
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/Base64/Base64EncryptionOptions.cs b/DevsDaddy/Shared/CryptoLibrary/Modules/Base64/Base64EncryptionOptions.cs
new file mode 100644
index 0000000..f89be3a
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/Base64/Base64EncryptionOptions.cs
@@ -0,0 +1,11 @@
+using System.Text;
+using DevsDaddy.Shared.CryptoLibrary.Core;
+
+namespace DevsDaddy.Shared.CryptoLibrary.Modules.Base64
+{
+ [System.Serializable]
+ public class Base64EncryptionOptions : IProviderOptions
+ {
+ public Encoding encoding = Encoding.UTF8;
+ }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/Base64/Base64EncryptionOptions.cs.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/Base64/Base64EncryptionOptions.cs.meta
new file mode 100644
index 0000000..cea1850
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/Base64/Base64EncryptionOptions.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: c3484dc302e545a993986d2e3fe21c31
+timeCreated: 1709890394
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/Base64/Base64Provider.cs b/DevsDaddy/Shared/CryptoLibrary/Modules/Base64/Base64Provider.cs
new file mode 100644
index 0000000..f169a48
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/Base64/Base64Provider.cs
@@ -0,0 +1,66 @@
+using System;
+using DevsDaddy.Shared.CryptoLibrary.Core;
+
+namespace DevsDaddy.Shared.CryptoLibrary.Modules.Base64
+{
+ ///
+ /// Base64 Encryption Provider.
+ /// Using for encrypt/decrypt plain text or byte arrays
+ ///
+ public class Base64Provider : ICryptoProvider
+ {
+ private Base64EncryptionOptions _options;
+
+ ///
+ /// Base64 Encryption Provider
+ ///
+ ///
+ public Base64Provider(Base64EncryptionOptions options = null) {
+ _options = options ?? new Base64EncryptionOptions();
+ }
+
+ ///
+ /// Decrypt Base64 string to plain text
+ ///
+ ///
+ ///
+ public string DecryptString(string encryptedString) {
+ byte[] decodedBytes = Convert.FromBase64String (encryptedString);
+ string decodedText = _options.encoding.GetString (decodedBytes);
+ return decodedText;
+ }
+
+ ///
+ /// Decrypt Base64 byte array to decrypted byte array
+ ///
+ ///
+ ///
+ public byte[] DecryptBinary(byte[] encryptedBinary) {
+ string encoded = _options.encoding.GetString(encryptedBinary);
+ byte[] decodedBytes = Convert.FromBase64String(encoded);
+ return decodedBytes;
+ }
+
+ ///
+ /// Encrypt plain-text to base64 string
+ ///
+ ///
+ ///
+ public string EncryptString(string decryptedString) {
+ byte[] bytesToEncode = _options.encoding.GetBytes (decryptedString);
+ string encodedText = Convert.ToBase64String (bytesToEncode);
+ return encodedText;
+ }
+
+ ///
+ /// Encrypt byte array to Base64 binary
+ ///
+ ///
+ ///
+ public byte[] EncryptBinary(byte[] decryptedBinary) {
+ string encodedText = Convert.ToBase64String(decryptedBinary);
+ byte[] encodedBytes = _options.encoding.GetBytes (encodedText);
+ return encodedBytes;
+ }
+ }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/Base64/Base64Provider.cs.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/Base64/Base64Provider.cs.meta
new file mode 100644
index 0000000..96f7b1e
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/Base64/Base64Provider.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: e306f37400714c7aad8a32136af895eb
+timeCreated: 1709890384
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/BlowFish.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/BlowFish.meta
new file mode 100644
index 0000000..84ab5f7
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/BlowFish.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: d79d2dc5556347c094e744ba1e21c395
+timeCreated: 1709897312
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/BlowFish/BlowfishEncryptionOptions.cs b/DevsDaddy/Shared/CryptoLibrary/Modules/BlowFish/BlowfishEncryptionOptions.cs
new file mode 100644
index 0000000..bf05e37
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/BlowFish/BlowfishEncryptionOptions.cs
@@ -0,0 +1,12 @@
+using System.Text;
+using DevsDaddy.Shared.CryptoLibrary.Core;
+
+namespace DevsDaddy.Shared.CryptoLibrary.Modules.BlowFish
+{
+ [System.Serializable]
+ public class BlowfishEncryptionOptions : IProviderOptions
+ {
+ public Encoding encoding = Encoding.UTF8;
+ public string cryptoKey = "MyCryptoKey";
+ }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/BlowFish/BlowfishEncryptionOptions.cs.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/BlowFish/BlowfishEncryptionOptions.cs.meta
new file mode 100644
index 0000000..bb51178
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/BlowFish/BlowfishEncryptionOptions.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 970075a8bcf84b42849dec0e3b47117e
+timeCreated: 1709901465
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/BlowFish/BlowfishProvider.cs b/DevsDaddy/Shared/CryptoLibrary/Modules/BlowFish/BlowfishProvider.cs
new file mode 100644
index 0000000..5b81797
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/BlowFish/BlowfishProvider.cs
@@ -0,0 +1,458 @@
+using DevsDaddy.Shared.CryptoLibrary.Core;
+using System;
+using System.IO;
+using System.Text;
+
+namespace DevsDaddy.Shared.CryptoLibrary.Modules.BlowFish
+{
+ ///
+ /// Blowfish Crypto Provider
+ ///
+ public class BlowfishProvider : ICryptoProvider
+ {
+ private BlowfishEncryptionOptions _options;
+
+ const int N = 16;
+ const int KEYBYTES = 8;
+
+ static uint[] _P =
+ {
+ 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0,
+ 0x082efa98, 0xec4e6c89, 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
+ 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, 0x9216d5d9, 0x8979fb1b
+ };
+ static uint[,] _S =
+ {
+ {
+ 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96,
+ 0xba7c9045, 0xf12c7f99, 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16,
+ 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e, 0x0d95748f, 0x728eb658,
+ 0x718bcd58, 0x82154aee, 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
+ 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, 0x8e79dcb0, 0x603a180e,
+ 0x6c9e0e8b, 0xb01e8a3e, 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60,
+ 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440, 0x55ca396a, 0x2aab10b6,
+ 0xb4cc5c34, 0x1141e8ce, 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
+ 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, 0xafd6ba33, 0x6c24cf5c,
+ 0x7a325381, 0x28958677, 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193,
+ 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032, 0xef845d5d, 0xe98575b1,
+ 0xdc262302, 0xeb651b88, 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
+ 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, 0x21c66842, 0xf6e96c9a,
+ 0x670c9c61, 0xabd388f0, 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3,
+ 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98, 0xa1f1651d, 0x39af0176,
+ 0x66ca593e, 0x82430e88, 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
+ 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, 0x4ed3aa62, 0x363f7706,
+ 0x1bfedf72, 0x429b023d, 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b,
+ 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7, 0xe3fe501a, 0xb6794c3b,
+ 0x976ce0bd, 0x04c006ba, 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
+ 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, 0x6dfc511f, 0x9b30952c,
+ 0xcc814544, 0xaf5ebd09, 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3,
+ 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb, 0x5579c0bd, 0x1a60320a,
+ 0xd6a100c6, 0x402c7279, 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
+ 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, 0x323db5fa, 0xfd238760,
+ 0x53317b48, 0x3e00df82, 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db,
+ 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573, 0x695b27b0, 0xbbca58c8,
+ 0xe1ffa35d, 0xb8f011a0, 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
+ 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, 0xe1ddf2da, 0xa4cb7e33,
+ 0x62fb1341, 0xcee4c6e8, 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4,
+ 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0, 0xd08ed1d0, 0xafc725e0,
+ 0x8e3c5b2f, 0x8e7594b7, 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
+ 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, 0x2f2f2218, 0xbe0e1777,
+ 0xea752dfe, 0x8b021fa1, 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299,
+ 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9, 0x165fa266, 0x80957705,
+ 0x93cc7314, 0x211a1477, 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
+ 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, 0x00250e2d, 0x2071b35e,
+ 0x226800bb, 0x57b8e0af, 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa,
+ 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5, 0x83260376, 0x6295cfa9,
+ 0x11c81968, 0x4e734a41, 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
+ 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, 0x08ba6fb5, 0x571be91f,
+ 0xf296ec6b, 0x2a0dd915, 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664,
+ 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a
+ },
+ {
+ 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, 0xad6ea6b0, 0x49a7df7d,
+ 0x9cee60b8, 0x8fedb266, 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1,
+ 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e, 0x3f54989a, 0x5b429d65,
+ 0x6b8fe4d6, 0x99f73fd6, 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
+ 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, 0x09686b3f, 0x3ebaefc9,
+ 0x3c971814, 0x6b6a70a1, 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737,
+ 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8, 0xb03ada37, 0xf0500c0d,
+ 0xf01c1f04, 0x0200b3ff, 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
+ 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, 0x3ae5e581, 0x37c2dadc,
+ 0xc8b57634, 0x9af3dda7, 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41,
+ 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331, 0x4e548b38, 0x4f6db908,
+ 0x6f420d03, 0xf60a04bf, 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
+ 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, 0x5512721f, 0x2e6b7124,
+ 0x501adde6, 0x9f84cd87, 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c,
+ 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2, 0xef1c1847, 0x3215d908,
+ 0xdd433b37, 0x24c2ba16, 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
+ 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, 0x043556f1, 0xd7a3c76b,
+ 0x3c11183b, 0x5924a509, 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e,
+ 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3, 0x771fe71c, 0x4e3d06fa,
+ 0x2965dcb9, 0x99e71d0f, 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
+ 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, 0xf2f74ea7, 0x361d2b3d,
+ 0x1939260f, 0x19c27960, 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66,
+ 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28, 0xc332ddef, 0xbe6c5aa5,
+ 0x65582185, 0x68ab9802, 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
+ 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, 0x13cca830, 0xeb61bd96,
+ 0x0334fe1e, 0xaa0363cf, 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14,
+ 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e, 0x648b1eaf, 0x19bdf0ca,
+ 0xa02369b9, 0x655abb50, 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
+ 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, 0xf837889a, 0x97e32d77,
+ 0x11ed935f, 0x16681281, 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99,
+ 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696, 0xcdb30aeb, 0x532e3054,
+ 0x8fd948e4, 0x6dbc3128, 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
+ 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, 0x45eee2b6, 0xa3aaabea,
+ 0xdb6c4f15, 0xfacb4fd0, 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105,
+ 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250, 0xcf62a1f2, 0x5b8d2646,
+ 0xfc8883a0, 0xc1c7b6a3, 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
+ 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, 0x58428d2a, 0x0c55f5ea,
+ 0x1dadf43e, 0x233f7061, 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb,
+ 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e, 0xa6078084, 0x19f8509e,
+ 0xe8efd855, 0x61d99735, 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
+ 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, 0xdb73dbd3, 0x105588cd,
+ 0x675fda79, 0xe3674340, 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20,
+ 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7
+ },
+ {
+ 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, 0x411520f7, 0x7602d4f7,
+ 0xbcf46b2e, 0xd4a20068, 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af,
+ 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840, 0x4d95fc1d, 0x96b591af,
+ 0x70f4ddd3, 0x66a02f45, 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
+ 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, 0x28507825, 0x530429f4,
+ 0x0a2c86da, 0xe9b66dfb, 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee,
+ 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6, 0xaace1e7c, 0xd3375fec,
+ 0xce78a399, 0x406b2a42, 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
+ 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, 0x3a6efa74, 0xdd5b4332,
+ 0x6841e7f7, 0xca7820fb, 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527,
+ 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b, 0x55a867bc, 0xa1159a58,
+ 0xcca92963, 0x99e1db33, 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
+ 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, 0x95c11548, 0xe4c66d22,
+ 0x48c1133f, 0xc70f86dc, 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17,
+ 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564, 0x257b7834, 0x602a9c60,
+ 0xdff8e8a3, 0x1f636c1b, 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
+ 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, 0x85b2a20e, 0xe6ba0d99,
+ 0xde720c8c, 0x2da2f728, 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0,
+ 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e, 0x0a476341, 0x992eff74,
+ 0x3a6f6eab, 0xf4f8fd37, 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
+ 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, 0xf1290dc7, 0xcc00ffa3,
+ 0xb5390f92, 0x690fed0b, 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3,
+ 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb, 0x37392eb3, 0xcc115979,
+ 0x8026e297, 0xf42e312d, 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
+ 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, 0x1a6b1018, 0x11caedfa,
+ 0x3d25bdd8, 0xe2e1c3c9, 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a,
+ 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe, 0x9dbc8057, 0xf0f7c086,
+ 0x60787bf8, 0x6003604d, 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
+ 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, 0x77a057be, 0xbde8ae24,
+ 0x55464299, 0xbf582e61, 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2,
+ 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9, 0x7aeb2661, 0x8b1ddf84,
+ 0x846a0e79, 0x915f95e2, 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
+ 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, 0xb77f19b6, 0xe0a9dc09,
+ 0x662d09a1, 0xc4324633, 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10,
+ 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169, 0xdcb7da83, 0x573906fe,
+ 0xa1e2ce9b, 0x4fcd7f52, 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
+ 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, 0xf0177a28, 0xc0f586e0,
+ 0x006058aa, 0x30dc7d62, 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634,
+ 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76, 0x6f05e409, 0x4b7c0188,
+ 0x39720a3d, 0x7c927c24, 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
+ 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, 0x1e50ef5e, 0xb161e6f8,
+ 0xa28514d9, 0x6c51133c, 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837,
+ 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0
+ },
+ {
+ 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, 0x5cb0679e, 0x4fa33742,
+ 0xd3822740, 0x99bc9bbe, 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b,
+ 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4, 0x5748ab2f, 0xbc946e79,
+ 0xc6a376d2, 0x6549c2c8, 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
+ 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, 0xa1fad5f0, 0x6a2d519a,
+ 0x63ef8ce2, 0x9a86ee22, 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4,
+ 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6, 0x2826a2f9, 0xa73a3ae1,
+ 0x4ba99586, 0xef5562e9, 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
+ 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, 0xe990fd5a, 0x9e34d797,
+ 0x2cf0b7d9, 0x022b8b51, 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28,
+ 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c, 0xe029ac71, 0xe019a5e6,
+ 0x47b0acfd, 0xed93fa9b, 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
+ 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, 0x15056dd4, 0x88f46dba,
+ 0x03a16125, 0x0564f0bd, 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a,
+ 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319, 0x7533d928, 0xb155fdf5,
+ 0x03563482, 0x8aba3cbb, 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
+ 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, 0xea7a90c2, 0xfb3e7bce,
+ 0x5121ce64, 0x774fbe32, 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680,
+ 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166, 0xb39a460a, 0x6445c0dd,
+ 0x586cdecf, 0x1c20c8ae, 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
+ 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, 0x72eacea8, 0xfa6484bb,
+ 0x8d6612ae, 0xbf3c6f47, 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370,
+ 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d, 0x4040cb08, 0x4eb4e2cc,
+ 0x34d2466a, 0x0115af84, 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
+ 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, 0x611560b1, 0xe7933fdc,
+ 0xbb3a792b, 0x344525bd, 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9,
+ 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7, 0x1a908749, 0xd44fbd9a,
+ 0xd0dadecb, 0xd50ada38, 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
+ 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, 0xbf97222c, 0x15e6fc2a,
+ 0x0f91fc71, 0x9b941525, 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1,
+ 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442, 0xe0ec6e0e, 0x1698db3b,
+ 0x4c98a0be, 0x3278e964, 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
+ 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, 0xdf359f8d, 0x9b992f2e,
+ 0xe60b6f47, 0x0fe3f11d, 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f,
+ 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299, 0xf523f357, 0xa6327623,
+ 0x93a83531, 0x56cccd02, 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
+ 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, 0xe6c6c7bd, 0x327a140a,
+ 0x45e1d006, 0xc3f27b9a, 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6,
+ 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b, 0x53113ec0, 0x1640e3d3,
+ 0x38abbd60, 0x2547adf0, 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
+ 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, 0x1948c25c, 0x02fb8a8c,
+ 0x01c36ae4, 0xd6ebe1f9, 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f,
+ 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6
+ }
+ };
+
+ uint[] P;
+ uint[,] S;
+
+ ///
+ /// Blowfish Provider
+ ///
+ ///
+ public BlowfishProvider(BlowfishEncryptionOptions options) {
+ _options = options ?? new BlowfishEncryptionOptions();
+
+ byte[] key = _options.encoding.GetBytes(_options.cryptoKey);
+
+ short i;
+ short j;
+ short k;
+ uint data;
+ uint datal;
+ uint datar;
+
+ P = _P.Clone() as uint[];
+ S = _S.Clone() as uint[,];
+
+ j = 0;
+ for (i = 0; i < N + 2; ++i)
+ {
+ data = 0x00000000;
+ for (k = 0; k < 4; ++k)
+ {
+ data = (data << 8) | key[j];
+ j++;
+ if (j >= key.Length)
+ {
+ j = 0;
+ }
+ }
+ P[i] = P[i] ^ data;
+ }
+
+ datal = 0x00000000;
+ datar = 0x00000000;
+
+ for (i = 0; i < N + 2; i += 2)
+ {
+ Encipher(ref datal, ref datar);
+ P[i] = datal;
+ P[i + 1] = datar;
+ }
+
+ for (i = 0; i < 4; ++i)
+ {
+ for (j = 0; j < 256; j += 2)
+ {
+ Encipher(ref datal, ref datar);
+
+ S[i, j] = datal;
+ S[i, j + 1] = datar;
+ }
+ }
+ }
+
+ private uint F(uint x)
+ {
+ ushort a;
+ ushort b;
+ ushort c;
+ ushort d;
+ uint y;
+
+ d = (ushort)(x & 0x00FF);
+ x >>= 8;
+ c = (ushort)(x & 0x00FF);
+ x >>= 8;
+ b = (ushort)(x & 0x00FF);
+ x >>= 8;
+ a = (ushort)(x & 0x00FF);
+ //y = ((S[0][a] + S[1][b]) ^ S[2][c]) + S[3][d];
+ y = S[0, a] + S[1, b];
+ y = y ^ S[2, c];
+ y = y + S[3, d];
+
+ return y;
+ }
+
+ private void Encipher(byte[] data, int length)
+ {
+ uint xl, xr;
+ if ((length % 8) != 0)
+ throw new Exception("Invalid Length");
+ for (int i = 0; i < length; i += 8)
+ {
+ // Encode the data in 8 byte blocks.
+ xl = (uint)((data[i] << 24) | (data[i + 1] << 16) | (data[i + 2] << 8) | data[i + 3]);
+ xr = (uint)((data[i + 4] << 24) | (data[i + 5] << 16) | (data[i + 6] << 8) | data[i + 7]);
+ Encipher(ref xl, ref xr);
+ // Now Replace the data.
+ data[i] = (byte)(xl >> 24);
+ data[i + 1] = (byte)(xl >> 16);
+ data[i + 2] = (byte)(xl >> 8);
+ data[i + 3] = (byte)(xl);
+ data[i + 4] = (byte)(xr >> 24);
+ data[i + 5] = (byte)(xr >> 16);
+ data[i + 6] = (byte)(xr >> 8);
+ data[i + 7] = (byte)(xr);
+ }
+ }
+
+ private void Encipher(ref uint xl, ref uint xr)
+ {
+ uint Xl;
+ uint Xr;
+ uint temp;
+ short i;
+
+ Xl = xl;
+ Xr = xr;
+
+ for (i = 0; i < N; ++i)
+ {
+ Xl = Xl ^ P[i];
+ Xr = F(Xl) ^ Xr;
+
+ temp = Xl;
+ Xl = Xr;
+ Xr = temp;
+ }
+
+ temp = Xl;
+ Xl = Xr;
+ Xr = temp;
+
+ Xr = Xr ^ P[N];
+ Xl = Xl ^ P[N + 1];
+
+ xl = Xl;
+ xr = Xr;
+ }
+
+ private String Encipher(String data)
+ {
+ byte[] b = _options.encoding.GetBytes(data);
+ Encipher(b, b.Length);
+ return Convert.ToBase64String(b);
+ }
+
+ private void Decipher(byte[] data, int length)
+ {
+ uint xl, xr;
+ if ((length % 8) != 0)
+ throw new Exception("Invalid Length");
+ for (int i = 0; i < length; i += 8)
+ {
+ // Encode the data in 8 byte blocks.
+ xl = (uint)((data[i] << 24) | (data[i + 1] << 16) | (data[i + 2] << 8) | data[i + 3]);
+ xr = (uint)((data[i + 4] << 24) | (data[i + 5] << 16) | (data[i + 6] << 8) | data[i + 7]);
+ Decipher(ref xl, ref xr);
+ // Now Replace the data.
+ data[i] = (byte)(xl >> 24);
+ data[i + 1] = (byte)(xl >> 16);
+ data[i + 2] = (byte)(xl >> 8);
+ data[i + 3] = (byte)(xl);
+ data[i + 4] = (byte)(xr >> 24);
+ data[i + 5] = (byte)(xr >> 16);
+ data[i + 6] = (byte)(xr >> 8);
+ data[i + 7] = (byte)(xr);
+ }
+ }
+
+ private void Decipher(ref uint xl, ref uint xr)
+ {
+ uint Xl;
+ uint Xr;
+ uint temp;
+ short i;
+
+ Xl = xl;
+ Xr = xr;
+
+ for (i = N + 1; i > 1; --i)
+ {
+ Xl = Xl ^ P[i];
+ Xr = F(Xl) ^ Xr;
+
+ /* Exchange Xl and Xr */
+ temp = Xl;
+ Xl = Xr;
+ Xr = temp;
+ }
+
+ /* Exchange Xl and Xr */
+ temp = Xl;
+ Xl = Xr;
+ Xr = temp;
+
+ Xr = Xr ^ P[1];
+ Xl = Xl ^ P[0];
+
+ xl = Xl;
+ xr = Xr;
+ }
+
+ private String Decipher(String data)
+ {
+ byte[] b = Convert.FromBase64String(data);
+ Decipher(b, b.Length);
+
+ return _options.encoding.GetString(b);
+ }
+
+ ///
+ /// Decrypt text using Blowfish Provider
+ ///
+ ///
+ ///
+ public string DecryptString(string encryptedString) {
+ return Decipher(encryptedString);
+ }
+
+ ///
+ /// Decrypt byte array using Blowfish Provider
+ ///
+ ///
+ ///
+ public byte[] DecryptBinary(byte[] encryptedBinary) {
+ byte[] decrypted = new byte[encryptedBinary.Length];
+ Array.Copy(encryptedBinary, decrypted, encryptedBinary.Length);
+ Decipher(decrypted, decrypted.Length);
+ return decrypted;
+ }
+
+ ///
+ /// Encode plain-text using Blowfish Provider
+ ///
+ ///
+ ///
+ public string EncryptString(string decryptedString) {
+ return Encipher(decryptedString);
+ }
+
+ ///
+ /// Encrypt Binary using Blowfish Provider
+ ///
+ ///
+ ///
+ public byte[] EncryptBinary(byte[] decryptedBinary) {
+ byte[] encrypted = new byte[decryptedBinary.Length];
+ Array.Copy(decryptedBinary, encrypted, decryptedBinary.Length);
+ Decipher(encrypted, encrypted.Length);
+ return encrypted;
+ }
+ }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/BlowFish/BlowfishProvider.cs.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/BlowFish/BlowfishProvider.cs.meta
new file mode 100644
index 0000000..551d4f7
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/BlowFish/BlowfishProvider.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: c50802061af74e20ab21681d6addd0c1
+timeCreated: 1709901452
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/Crc32.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/Crc32.meta
new file mode 100644
index 0000000..3c1bed3
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/Crc32.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 7a00b48dbb944ac0a2d68a7beb1f4d74
+timeCreated: 1709901092
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/Crc32/CRC32EncryptionOptions.cs b/DevsDaddy/Shared/CryptoLibrary/Modules/Crc32/CRC32EncryptionOptions.cs
new file mode 100644
index 0000000..8bf0dac
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/Crc32/CRC32EncryptionOptions.cs
@@ -0,0 +1,11 @@
+using System.Text;
+using DevsDaddy.Shared.CryptoLibrary.Core;
+
+namespace DevsDaddy.Shared.CryptoLibrary.Modules.Crc32
+{
+ [System.Serializable]
+ public class CRC32EncryptionOptions : IProviderOptions
+ {
+ public Encoding encoding = Encoding.UTF8;
+ }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/Crc32/CRC32EncryptionOptions.cs.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/Crc32/CRC32EncryptionOptions.cs.meta
new file mode 100644
index 0000000..50383dd
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/Crc32/CRC32EncryptionOptions.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: c88999e508ec47fda502137b21747ede
+timeCreated: 1709901131
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/Crc32/CRC32Provider.cs b/DevsDaddy/Shared/CryptoLibrary/Modules/Crc32/CRC32Provider.cs
new file mode 100644
index 0000000..ea87a5d
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/Crc32/CRC32Provider.cs
@@ -0,0 +1,65 @@
+using System;
+using DevsDaddy.Shared.CryptoLibrary.Core;
+
+namespace DevsDaddy.Shared.CryptoLibrary.Modules.Crc32
+{
+ ///
+ /// CRC32 Hash Provider
+ ///
+ public class CRC32Provider : ICryptoProvider
+ {
+ // Provider Options
+ private CRC32EncryptionOptions _options;
+
+ ///
+ /// CRC32 Hash Provider
+ ///
+ ///
+ public CRC32Provider(CRC32EncryptionOptions options = null) {
+ _options = options ?? new CRC32EncryptionOptions();
+ }
+
+ ///
+ /// Decrypt String (Not Supported for hashing)
+ ///
+ ///
+ ///
+ ///
+ public string DecryptString(string encryptedString) {
+ throw new Exception($"Failed to decrypt text, because {this.GetType()} doesn't support decryption.");
+ }
+
+ ///
+ /// Decrypt Binary (Not Supported for hashing)
+ ///
+ ///
+ ///
+ ///
+ public byte[] DecryptBinary(byte[] encryptedBinary) {
+ throw new Exception($"Failed to decrypt text, because {this.GetType()} doesn't support decryption.");
+ }
+
+ ///
+ /// Get CRC32 of Plain Text
+ ///
+ ///
+ ///
+ public string EncryptString(string decryptedString) {
+ byte[] encrypted = EncryptBinary(_options.encoding.GetBytes(decryptedString));
+ return Convert.ToBase64String(encrypted);
+ }
+
+ ///
+ /// Encrypt Binary
+ ///
+ ///
+ ///
+ public byte[] EncryptBinary(byte[] decryptedBinary) {
+ using (Crc32 crc = new Crc32())
+ {
+ byte[] hashBytes = crc.ComputeHash(decryptedBinary);
+ return hashBytes;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/Crc32/CRC32Provider.cs.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/Crc32/CRC32Provider.cs.meta
new file mode 100644
index 0000000..04c2af4
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/Crc32/CRC32Provider.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 32e98cf987fa4d4ba5950846eccf09d8
+timeCreated: 1709901123
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/Crc32/Crc32.cs b/DevsDaddy/Shared/CryptoLibrary/Modules/Crc32/Crc32.cs
new file mode 100644
index 0000000..e59da9e
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/Crc32/Crc32.cs
@@ -0,0 +1,110 @@
+using System;
+using System.Security.Cryptography;
+using System.IO;
+
+namespace DevsDaddy.Shared.CryptoLibrary.Modules.Crc32
+{
+ public class Crc32 : HashAlgorithm
+ {
+ public const UInt32 DefaultPolynomial = 0xedb88320;
+ public const UInt32 DefaultSeed = 0xffffffff;
+
+ private UInt32 hash;
+ private UInt32 seed;
+ private UInt32[] table;
+ private static UInt32[] defaultTable;
+
+ public Crc32() {
+ table = InitializeTable(DefaultPolynomial);
+ seed = DefaultSeed;
+ Initialize();
+ }
+
+ public Crc32(UInt32 polynomial, UInt32 seed) {
+ table = InitializeTable(polynomial);
+ this.seed = seed;
+ Initialize();
+ }
+
+ public override void Initialize() {
+ hash = seed;
+ }
+
+ protected override void HashCore(byte[] buffer, int start, int length) {
+ hash = CalculateHash(table, hash, buffer, start, length);
+ }
+
+ protected override byte[] HashFinal() {
+ byte[] hashBuffer = UInt32ToBigEndianBytes(~hash);
+ this.HashValue = hashBuffer;
+ return hashBuffer;
+ }
+
+ public override int HashSize {
+ get { return 32; }
+ }
+
+ public static UInt32 Compute(byte[] buffer) {
+ return ~CalculateHash(InitializeTable(DefaultPolynomial), DefaultSeed, buffer, 0, buffer.Length);
+ }
+
+ public static UInt32 Compute(UInt32 seed, byte[] buffer) {
+ return ~CalculateHash(InitializeTable(DefaultPolynomial), seed, buffer, 0, buffer.Length);
+ }
+
+ public static UInt32 Compute(UInt32 polynomial, UInt32 seed, byte[] buffer) {
+ return ~CalculateHash(InitializeTable(polynomial), seed, buffer, 0, buffer.Length);
+ }
+
+ private static UInt32[] InitializeTable(UInt32 polynomial) {
+ if (polynomial == DefaultPolynomial && defaultTable != null)
+ return defaultTable;
+
+ UInt32[] createTable = new UInt32[256];
+ for (int i = 0; i < 256; i++)
+ {
+ UInt32 entry = (UInt32)i;
+ for (int j = 0; j < 8; j++)
+ if ((entry & 1) == 1)
+ entry = (entry >> 1) ^ polynomial;
+ else
+ entry = entry >> 1;
+ createTable[i] = entry;
+ }
+
+ if (polynomial == DefaultPolynomial)
+ defaultTable = createTable;
+
+ return createTable;
+ }
+
+ private static UInt32 CalculateHash(UInt32[] table, UInt32 seed, byte[] buffer, int start, int size) {
+ UInt32 crc = seed;
+ for (int i = start; i < size; i++)
+ unchecked
+ {
+ crc = (crc >> 8) ^ table[buffer[i] ^ crc & 0xff];
+ }
+ return crc;
+ }
+
+ private byte[] UInt32ToBigEndianBytes(UInt32 x) {
+ return new byte[] {
+ (byte)((x >> 24) & 0xff),
+ (byte)((x >> 16) & 0xff),
+ (byte)((x >> 8) & 0xff),
+ (byte)(x & 0xff)
+ };
+ }
+
+ public string Get(string FilePath) {
+ Crc32 crc32 = new Crc32();
+ String hash = String.Empty;
+
+ using (FileStream fs = File.Open(FilePath, FileMode.Open))
+ foreach (byte b in crc32.ComputeHash(fs)) hash += b.ToString("x2").ToLower();
+
+ return hash;
+ }
+ }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/Crc32/Crc32.cs.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/Crc32/Crc32.cs.meta
new file mode 100644
index 0000000..f82784a
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/Crc32/Crc32.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 5b306395bd914c1ea1be614cf0fffbe6
+timeCreated: 1709901203
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/DES.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/DES.meta
new file mode 100644
index 0000000..91c04de
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/DES.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 7331c9adf98140a99fa8d992ae7f851c
+timeCreated: 1709891836
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/DES/DESEncryptionOptions.cs b/DevsDaddy/Shared/CryptoLibrary/Modules/DES/DESEncryptionOptions.cs
new file mode 100644
index 0000000..5b720b8
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/DES/DESEncryptionOptions.cs
@@ -0,0 +1,12 @@
+using System.Text;
+using DevsDaddy.Shared.CryptoLibrary.Core;
+
+namespace DevsDaddy.Shared.CryptoLibrary.Modules.DES
+{
+ [System.Serializable]
+ public class DESEncryptionOptions : IProviderOptions
+ {
+ public string cryptoKey = "ABCDEFGH";
+ public Encoding encoding = Encoding.UTF8;
+ }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/DES/DESEncryptionOptions.cs.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/DES/DESEncryptionOptions.cs.meta
new file mode 100644
index 0000000..46f2417
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/DES/DESEncryptionOptions.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 7d4e5d2be20b40d284b39199847a26f0
+timeCreated: 1709891855
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/DES/DESProvider.cs b/DevsDaddy/Shared/CryptoLibrary/Modules/DES/DESProvider.cs
new file mode 100644
index 0000000..974936f
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/DES/DESProvider.cs
@@ -0,0 +1,98 @@
+using System;
+using System.IO;
+using System.Security.Cryptography;
+using DevsDaddy.Shared.CryptoLibrary.Core;
+
+namespace DevsDaddy.Shared.CryptoLibrary.Modules.DES
+{
+ ///
+ /// DES Encryption Provider.
+ /// Using for encrypt/decrypt plain text or byte arrays
+ ///
+ public class DESProvider : ICryptoProvider
+ {
+ // Encryption Options
+ private DESEncryptionOptions _options;
+
+ ///
+ /// DES Encryption Provider
+ ///
+ ///
+ public DESProvider(DESEncryptionOptions options = null) {
+ _options = options ?? new DESEncryptionOptions();
+ }
+
+ ///
+ /// Decrypt encrypted string to plain text using DES
+ ///
+ ///
+ ///
+ public string DecryptString(string encryptedString) {
+ byte[] txtByteData = Convert.FromBase64String(encryptedString);
+ byte[] decoded = DecryptBinary(txtByteData);
+ return _options.encoding.GetString(decoded);
+ }
+
+ ///
+ /// Decrypt encrypted byte array to decrypted byte array using DES
+ ///
+ ///
+ ///
+ public byte[] DecryptBinary(byte[] encryptedBinary) {
+ byte[] keyByteData = _options.encoding.GetBytes(_options.cryptoKey);
+
+ DESCryptoServiceProvider DEScryptoProvider = new DESCryptoServiceProvider();
+ ICryptoTransform trnsfrm = DEScryptoProvider.CreateDecryptor(keyByteData, keyByteData);
+ CryptoStreamMode mode = CryptoStreamMode.Write;
+
+ //Set up Stream & Write Encript data
+ MemoryStream mStream = new MemoryStream();
+ CryptoStream cStream = new CryptoStream(mStream, trnsfrm, mode);
+ cStream.Write(encryptedBinary, 0, encryptedBinary.Length);
+ cStream.FlushFinalBlock();
+
+ //Read Ecncrypted Data From Memory Stream
+ byte[] result = new byte[mStream.Length];
+ mStream.Position = 0;
+ mStream.Read(result, 0, result.Length);
+
+ return result;
+ }
+
+ ///
+ /// Encrypt plain-text using DES
+ ///
+ ///
+ ///
+ public string EncryptString(string decryptedString) {
+ byte[] txtByteData = _options.encoding.GetBytes(decryptedString);
+ byte[] encoded = EncryptBinary(txtByteData);
+ return Convert.ToBase64String(encoded);
+ }
+
+ ///
+ /// Encrypt byte-array using DES
+ ///
+ ///
+ ///
+ public byte[] EncryptBinary(byte[] decryptedBinary) {
+ byte[] keyByteData = _options.encoding.GetBytes(_options.cryptoKey);
+ DESCryptoServiceProvider DEScryptoProvider = new DESCryptoServiceProvider();
+ ICryptoTransform trnsfrm = DEScryptoProvider.CreateEncryptor(keyByteData, keyByteData);
+ CryptoStreamMode mode = CryptoStreamMode.Write;
+
+ //Set up Stream & Write Encript data
+ MemoryStream mStream = new MemoryStream();
+ CryptoStream cStream = new CryptoStream(mStream, trnsfrm, mode);
+ cStream.Write(decryptedBinary, 0, decryptedBinary.Length);
+ cStream.FlushFinalBlock();
+
+ //Read Ecncrypted Data From Memory Stream
+ byte[] result = new byte[mStream.Length];
+ mStream.Position = 0;
+ mStream.Read(result, 0, result.Length);
+
+ return result;
+ }
+ }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/DES/DESProvider.cs.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/DES/DESProvider.cs.meta
new file mode 100644
index 0000000..54e1d37
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/DES/DESProvider.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: f97ecf2e80fd4695be93a4faf86a6b0f
+timeCreated: 1709891843
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/MD5.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/MD5.meta
new file mode 100644
index 0000000..2549996
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/MD5.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 709b5e3fc5ab4a628f158df4ea242698
+timeCreated: 1709889633
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/MD5/MD5EncryptionOptions.cs b/DevsDaddy/Shared/CryptoLibrary/Modules/MD5/MD5EncryptionOptions.cs
new file mode 100644
index 0000000..92c1df4
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/MD5/MD5EncryptionOptions.cs
@@ -0,0 +1,11 @@
+using System.Text;
+using DevsDaddy.Shared.CryptoLibrary.Core;
+
+namespace DevsDaddy.Shared.CryptoLibrary.Modules.MD5
+{
+ [System.Serializable]
+ public class MD5EncryptionOptions : IProviderOptions
+ {
+ public Encoding encoding = Encoding.UTF8;
+ }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/MD5/MD5EncryptionOptions.cs.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/MD5/MD5EncryptionOptions.cs.meta
new file mode 100644
index 0000000..a13a066
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/MD5/MD5EncryptionOptions.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 8de0da8afd9b4da5b2d8c8bd995ce70f
+timeCreated: 1709894165
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/MD5/MD5Provider.cs b/DevsDaddy/Shared/CryptoLibrary/Modules/MD5/MD5Provider.cs
new file mode 100644
index 0000000..1f5a5b5
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/MD5/MD5Provider.cs
@@ -0,0 +1,77 @@
+using System;
+using System.Text;
+using DevsDaddy.Shared.CryptoLibrary.Core;
+
+namespace DevsDaddy.Shared.CryptoLibrary.Modules.MD5
+{
+ ///
+ /// MD5 Hash Provider (No Decryption, Only Encryption)
+ ///
+ public class MD5Provider : ICryptoProvider
+ {
+ // Provider Options
+ private MD5EncryptionOptions _options;
+
+ ///
+ /// MD5 Hashing Provider
+ ///
+ ///
+ public MD5Provider(MD5EncryptionOptions options = null) {
+ _options = options ?? new MD5EncryptionOptions();
+ }
+
+ ///
+ /// Decrypt String (Not Supported for hashing)
+ ///
+ ///
+ ///
+ ///
+ public string DecryptString(string encryptedString) {
+ throw new Exception($"Failed to decrypt text, because {this.GetType()} doesn't support decryption.");
+ }
+
+ ///
+ /// Decrypt Binary (Not Supported for hashing)
+ ///
+ ///
+ ///
+ ///
+ public byte[] DecryptBinary(byte[] encryptedBinary) {
+ throw new Exception($"Failed to decrypt text, because {this.GetType()} doesn't support decryption.");
+ }
+
+ ///
+ /// Encrypt plain-text and returns MD5 hash
+ ///
+ ///
+ ///
+ public string EncryptString(string decryptedString) {
+ using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
+ {
+ byte[] inputBytes = _options.encoding.GetBytes(decryptedString);
+ byte[] hashBytes = md5.ComputeHash(inputBytes);
+
+ // Convert the byte array to hexadecimal string
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < hashBytes.Length; i++)
+ {
+ sb.Append(hashBytes[i].ToString("X2"));
+ }
+ return sb.ToString();
+ }
+ }
+
+ ///
+ /// Encrypt byte array and return MD5 hashed byte array
+ ///
+ ///
+ ///
+ public byte[] EncryptBinary(byte[] decryptedBinary) {
+ using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
+ {
+ byte[] hashBytes = md5.ComputeHash(decryptedBinary);
+ return hashBytes;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/MD5/MD5Provider.cs.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/MD5/MD5Provider.cs.meta
new file mode 100644
index 0000000..d4e9cfc
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/MD5/MD5Provider.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: ee97b4162c6c4e1cb68e88ab196c2028
+timeCreated: 1709894172
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/PBKDF2.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/PBKDF2.meta
new file mode 100644
index 0000000..997b845
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/PBKDF2.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 34c2bd6fc94d4b1c9f8d55f1e3ea6f93
+timeCreated: 1709898865
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/PBKDF2/PBKDF2EncryptionOptions.cs b/DevsDaddy/Shared/CryptoLibrary/Modules/PBKDF2/PBKDF2EncryptionOptions.cs
new file mode 100644
index 0000000..b7f3680
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/PBKDF2/PBKDF2EncryptionOptions.cs
@@ -0,0 +1,14 @@
+using System.Text;
+using DevsDaddy.Shared.CryptoLibrary.Core;
+
+namespace DevsDaddy.Shared.CryptoLibrary.Modules.PBKDF2
+{
+ [System.Serializable]
+ public class PBKDF2EncryptionOptions : IProviderOptions
+ {
+ public bool autoRegenerateSalt = true;
+ public Encoding encoding = Encoding.UTF8;
+ public int hashIterations = 100000;
+ public int saltSize = 34;
+ }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/PBKDF2/PBKDF2EncryptionOptions.cs.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/PBKDF2/PBKDF2EncryptionOptions.cs.meta
new file mode 100644
index 0000000..7e11cb9
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/PBKDF2/PBKDF2EncryptionOptions.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 5913aff3da074d73bf59d501328a333e
+timeCreated: 1709898878
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/PBKDF2/PBKDF2Provider.cs b/DevsDaddy/Shared/CryptoLibrary/Modules/PBKDF2/PBKDF2Provider.cs
new file mode 100644
index 0000000..673313c
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/PBKDF2/PBKDF2Provider.cs
@@ -0,0 +1,126 @@
+using System;
+using System.Security.Cryptography;
+using DevsDaddy.Shared.CryptoLibrary.Core;
+
+namespace DevsDaddy.Shared.CryptoLibrary.Modules.PBKDF2
+{
+ ///
+ /// PBKDF2 Hashing Provider
+ ///
+ public class PBKDF2Provider : ICryptoProvider
+ {
+ // Provider Options
+ private PBKDF2EncryptionOptions _options;
+ private string currentSalt;
+
+ ///
+ /// PBKDF2 Provider
+ ///
+ ///
+ public PBKDF2Provider(PBKDF2EncryptionOptions options = null) {
+ _options = options ?? new PBKDF2EncryptionOptions();
+ }
+
+ ///
+ /// Decrypt String (Not Supported for hashing)
+ ///
+ ///
+ ///
+ ///
+ public string DecryptString(string encryptedString) {
+ throw new Exception($"Failed to decrypt text, because {this.GetType()} doesn't support decryption.");
+ }
+
+ ///
+ /// Decrypt Binary (Not Supported for hashing)
+ ///
+ ///
+ ///
+ ///
+ public byte[] DecryptBinary(byte[] encryptedBinary) {
+ throw new Exception($"Failed to decrypt text, because {this.GetType()} doesn't support decryption.");
+ }
+
+ ///
+ /// Get PBKDF2 Hash from plain-text
+ ///
+ ///
+ ///
+ public string EncryptString(string decryptedString) {
+ if (string.IsNullOrEmpty(currentSalt) || _options.autoRegenerateSalt) GenerateSalt();
+ return calculateHash(_options.hashIterations, decryptedString);
+ }
+
+ ///
+ /// Get PBKDF2 Hash from byte array
+ ///
+ ///
+ ///
+ public byte[] EncryptBinary(byte[] decryptedBinary) {
+ if (string.IsNullOrEmpty(currentSalt) || _options.autoRegenerateSalt) GenerateSalt();
+ return calculateHash(_options.hashIterations, decryptedBinary);
+ }
+
+ ///
+ /// Generate Hash Salt
+ ///
+ ///
+ ///
+ public string GenerateSalt()
+ {
+ if (_options.saltSize < 1)
+ throw new InvalidOperationException(string.Format("Cannot generate a salt of size {0}, use a value greater than 1, recommended: 16", _options.saltSize));
+
+ var rand = RandomNumberGenerator.Create();
+ var ret = new byte[_options.saltSize];
+ rand.GetBytes(ret);
+
+ currentSalt = string.Format("{0}.{1}", _options.hashIterations, Convert.ToBase64String(ret));
+ return currentSalt;
+ }
+
+ ///
+ /// Calculate Text Hash
+ ///
+ ///
+ ///
+ ///
+ private string calculateHash(int iteration, string text)
+ {
+ byte[] saltBytes = _options.encoding.GetBytes(currentSalt);
+ var pbkdf2 = new Rfc2898DeriveBytes(text, saltBytes, iteration);
+ var key = pbkdf2.GetBytes(64);
+ return Convert.ToBase64String(key);
+ }
+
+ ///
+ /// Calculate Binary Hash
+ ///
+ ///
+ ///
+ ///
+ private byte[] calculateHash(int iteration, byte[] data) {
+ byte[] saltBytes = _options.encoding.GetBytes(currentSalt);
+ var pbkdf2 = new Rfc2898DeriveBytes(data, saltBytes, iteration);
+ var key = pbkdf2.GetBytes(64);
+ return key;
+ }
+
+ ///
+ /// Expand Salt
+ ///
+ ///
+ private void expandSalt()
+ {
+ try
+ {
+ var i = currentSalt.IndexOf('.');
+ _options.hashIterations = int.Parse(currentSalt.Substring(0, i), System.Globalization.NumberStyles.Number);
+ }
+ catch (Exception)
+ {
+ throw new FormatException("The salt was not in an expected format of {int}.{string}");
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/PBKDF2/PBKDF2Provider.cs.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/PBKDF2/PBKDF2Provider.cs.meta
new file mode 100644
index 0000000..7c2ee68
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/PBKDF2/PBKDF2Provider.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: b5d0e6204e3048ee9720ecfc78f8e958
+timeCreated: 1709898883
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/RIPEMD-160.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/RIPEMD-160.meta
new file mode 100644
index 0000000..6a270fb
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/RIPEMD-160.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 9592fbdc5acf4a61b4e6717e1596b69b
+timeCreated: 1709897338
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/RIPEMD-160/RIPEMD160.cs b/DevsDaddy/Shared/CryptoLibrary/Modules/RIPEMD-160/RIPEMD160.cs
new file mode 100644
index 0000000..0d5d8b7
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/RIPEMD-160/RIPEMD160.cs
@@ -0,0 +1,17 @@
+namespace DevsDaddy.Shared.CryptoLibrary.Modules.RIPEMD_160
+{
+ public abstract class RIPEMD160 : System.Security.Cryptography.HashAlgorithm
+ {
+ public RIPEMD160() { }
+
+ public new static RIPEMD160 Create()
+ {
+ return new RIPEMD160Managed();
+ }
+
+ public new static RIPEMD160 Create(string hashname)
+ {
+ return new RIPEMD160Managed();
+ }
+ }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/RIPEMD-160/RIPEMD160.cs.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/RIPEMD-160/RIPEMD160.cs.meta
new file mode 100644
index 0000000..12d7793
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/RIPEMD-160/RIPEMD160.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: c31d9ebcea784ab18e1443e8656abe00
+timeCreated: 1709898451
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/RIPEMD-160/RIPEMD160Managed.cs b/DevsDaddy/Shared/CryptoLibrary/Modules/RIPEMD-160/RIPEMD160Managed.cs
new file mode 100644
index 0000000..a60a4ff
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/RIPEMD-160/RIPEMD160Managed.cs
@@ -0,0 +1,444 @@
+using System;
+using System.Linq;
+using System.Text;
+
+namespace DevsDaddy.Shared.CryptoLibrary.Modules.RIPEMD_160
+{
+ public class RIPEMD160Managed : RIPEMD160
+ {
+ static public UInt32 ReadUInt32(byte[] buffer, long offset)
+ {
+ return
+ (Convert.ToUInt32(buffer[3 + offset]) << 24) |
+ (Convert.ToUInt32(buffer[2 + offset]) << 16) |
+ (Convert.ToUInt32(buffer[1 + offset]) << 8) |
+ (Convert.ToUInt32(buffer[0 + offset]));
+ }
+
+ static UInt32 RotateLeft(UInt32 value, int bits)
+ {
+ return (value << bits) | (value >> (32 - bits));
+ }
+
+ static UInt32 F(UInt32 x, UInt32 y, UInt32 z)
+ {
+ return x ^ y ^ z;
+ }
+
+ static UInt32 G(UInt32 x, UInt32 y, UInt32 z)
+ {
+ return (x & y) | (~x & z);
+ }
+
+ static UInt32 H(UInt32 x, UInt32 y, UInt32 z)
+ {
+ return (x | ~y) ^ z;
+ }
+
+ static UInt32 I(UInt32 x, UInt32 y, UInt32 z)
+ {
+ return (x & z) | (y & ~z);
+ }
+
+ static UInt32 J(UInt32 x, UInt32 y, UInt32 z)
+ {
+ return x ^ (y | ~z);
+ }
+
+ static void FF(ref UInt32 a, UInt32 b, ref UInt32 c, UInt32 d, UInt32 e, UInt32 x, int s)
+ {
+ a += F(b, c, d) + x;
+ a = RotateLeft(a, s) + e;
+ c = RotateLeft(c, 10);
+ }
+
+ static void GG(ref UInt32 a, UInt32 b, ref UInt32 c, UInt32 d, UInt32 e, UInt32 x, int s)
+ {
+ a += G(b, c, d) + x + (UInt32)0x5a827999;
+ a = RotateLeft(a, s) + e;
+ c = RotateLeft(c, 10);
+ }
+
+ static void HH(ref UInt32 a, UInt32 b, ref UInt32 c, UInt32 d, UInt32 e, UInt32 x, int s)
+ {
+ a += H(b, c, d) + x + (UInt32)0x6ed9eba1;
+ a = RotateLeft(a, s) + e;
+ c = RotateLeft(c, 10);
+ }
+
+ static void II(ref UInt32 a, UInt32 b, ref UInt32 c, UInt32 d, UInt32 e, UInt32 x, int s)
+ {
+ a += I(b, c, d) + x + (UInt32)0x8f1bbcdc;
+ a = RotateLeft(a, s) + e;
+ c = RotateLeft(c, 10);
+ }
+
+ static void JJ(ref UInt32 a, UInt32 b, ref UInt32 c, UInt32 d, UInt32 e, UInt32 x, int s)
+ {
+ a += J(b, c, d) + x + (UInt32)0xa953fd4e;
+ a = RotateLeft(a, s) + e;
+ c = RotateLeft(c, 10);
+ }
+
+ static void FFF(ref UInt32 a, UInt32 b, ref UInt32 c, UInt32 d, UInt32 e, UInt32 x, int s)
+ {
+ a += F(b, c, d) + x;
+ a = RotateLeft(a, s) + e;
+ c = RotateLeft(c, 10);
+ }
+
+ static void GGG(ref UInt32 a, UInt32 b, ref UInt32 c, UInt32 d, UInt32 e, UInt32 x, int s)
+ {
+ a += G(b, c, d) + x + (UInt32)0x7a6d76e9;
+ a = RotateLeft(a, s) + e;
+ c = RotateLeft(c, 10);
+ }
+
+ static void HHH(ref UInt32 a, UInt32 b, ref UInt32 c, UInt32 d, UInt32 e, UInt32 x, int s)
+ {
+ a += H(b, c, d) + x + (UInt32)0x6d703ef3;
+ a = RotateLeft(a, s) + e;
+ c = RotateLeft(c, 10);
+ }
+
+ static void III(ref UInt32 a, UInt32 b, ref UInt32 c, UInt32 d, UInt32 e, UInt32 x, int s)
+ {
+ a += I(b, c, d) + x + (UInt32)0x5c4dd124;
+ a = RotateLeft(a, s) + e;
+ c = RotateLeft(c, 10);
+ }
+
+ static void JJJ(ref UInt32 a, UInt32 b, ref UInt32 c, UInt32 d, UInt32 e, UInt32 x, int s)
+ {
+ a += J(b, c, d) + x + (UInt32)0x50a28be6;
+ a = RotateLeft(a, s) + e;
+ c = RotateLeft(c, 10);
+ }
+
+ static public void MDinit(ref UInt32[] MDbuf)
+ {
+ MDbuf[0] = (UInt32)0x67452301;
+ MDbuf[1] = (UInt32)0xefcdab89;
+ MDbuf[2] = (UInt32)0x98badcfe;
+ MDbuf[3] = (UInt32)0x10325476;
+ MDbuf[4] = (UInt32)0xc3d2e1f0;
+ }
+
+ static public void compress(ref UInt32[] MDbuf, UInt32[] X)
+ {
+ UInt32 aa = MDbuf[0];
+ UInt32 bb = MDbuf[1];
+ UInt32 cc = MDbuf[2];
+ UInt32 dd = MDbuf[3];
+ UInt32 ee = MDbuf[4];
+ UInt32 aaa = MDbuf[0];
+ UInt32 bbb = MDbuf[1];
+ UInt32 ccc = MDbuf[2];
+ UInt32 ddd = MDbuf[3];
+ UInt32 eee = MDbuf[4];
+
+ /* round 1 */
+ FF(ref aa, bb, ref cc, dd, ee, X[0], 11);
+ FF(ref ee, aa, ref bb, cc, dd, X[1], 14);
+ FF(ref dd, ee, ref aa, bb, cc, X[2], 15);
+ FF(ref cc, dd, ref ee, aa, bb, X[3], 12);
+ FF(ref bb, cc, ref dd, ee, aa, X[4], 5);
+ FF(ref aa, bb, ref cc, dd, ee, X[5], 8);
+ FF(ref ee, aa, ref bb, cc, dd, X[6], 7);
+ FF(ref dd, ee, ref aa, bb, cc, X[7], 9);
+ FF(ref cc, dd, ref ee, aa, bb, X[8], 11);
+ FF(ref bb, cc, ref dd, ee, aa, X[9], 13);
+ FF(ref aa, bb, ref cc, dd, ee, X[10], 14);
+ FF(ref ee, aa, ref bb, cc, dd, X[11], 15);
+ FF(ref dd, ee, ref aa, bb, cc, X[12], 6);
+ FF(ref cc, dd, ref ee, aa, bb, X[13], 7);
+ FF(ref bb, cc, ref dd, ee, aa, X[14], 9);
+ FF(ref aa, bb, ref cc, dd, ee, X[15], 8);
+
+ /* round 2 */
+ GG(ref ee, aa, ref bb, cc, dd, X[7], 7);
+ GG(ref dd, ee, ref aa, bb, cc, X[4], 6);
+ GG(ref cc, dd, ref ee, aa, bb, X[13], 8);
+ GG(ref bb, cc, ref dd, ee, aa, X[1], 13);
+ GG(ref aa, bb, ref cc, dd, ee, X[10], 11);
+ GG(ref ee, aa, ref bb, cc, dd, X[6], 9);
+ GG(ref dd, ee, ref aa, bb, cc, X[15], 7);
+ GG(ref cc, dd, ref ee, aa, bb, X[3], 15);
+ GG(ref bb, cc, ref dd, ee, aa, X[12], 7);
+ GG(ref aa, bb, ref cc, dd, ee, X[0], 12);
+ GG(ref ee, aa, ref bb, cc, dd, X[9], 15);
+ GG(ref dd, ee, ref aa, bb, cc, X[5], 9);
+ GG(ref cc, dd, ref ee, aa, bb, X[2], 11);
+ GG(ref bb, cc, ref dd, ee, aa, X[14], 7);
+ GG(ref aa, bb, ref cc, dd, ee, X[11], 13);
+ GG(ref ee, aa, ref bb, cc, dd, X[8], 12);
+
+ /* round 3 */
+ HH(ref dd, ee, ref aa, bb, cc, X[3], 11);
+ HH(ref cc, dd, ref ee, aa, bb, X[10], 13);
+ HH(ref bb, cc, ref dd, ee, aa, X[14], 6);
+ HH(ref aa, bb, ref cc, dd, ee, X[4], 7);
+ HH(ref ee, aa, ref bb, cc, dd, X[9], 14);
+ HH(ref dd, ee, ref aa, bb, cc, X[15], 9);
+ HH(ref cc, dd, ref ee, aa, bb, X[8], 13);
+ HH(ref bb, cc, ref dd, ee, aa, X[1], 15);
+ HH(ref aa, bb, ref cc, dd, ee, X[2], 14);
+ HH(ref ee, aa, ref bb, cc, dd, X[7], 8);
+ HH(ref dd, ee, ref aa, bb, cc, X[0], 13);
+ HH(ref cc, dd, ref ee, aa, bb, X[6], 6);
+ HH(ref bb, cc, ref dd, ee, aa, X[13], 5);
+ HH(ref aa, bb, ref cc, dd, ee, X[11], 12);
+ HH(ref ee, aa, ref bb, cc, dd, X[5], 7);
+ HH(ref dd, ee, ref aa, bb, cc, X[12], 5);
+
+ /* round 4 */
+ II(ref cc, dd, ref ee, aa, bb, X[1], 11);
+ II(ref bb, cc, ref dd, ee, aa, X[9], 12);
+ II(ref aa, bb, ref cc, dd, ee, X[11], 14);
+ II(ref ee, aa, ref bb, cc, dd, X[10], 15);
+ II(ref dd, ee, ref aa, bb, cc, X[0], 14);
+ II(ref cc, dd, ref ee, aa, bb, X[8], 15);
+ II(ref bb, cc, ref dd, ee, aa, X[12], 9);
+ II(ref aa, bb, ref cc, dd, ee, X[4], 8);
+ II(ref ee, aa, ref bb, cc, dd, X[13], 9);
+ II(ref dd, ee, ref aa, bb, cc, X[3], 14);
+ II(ref cc, dd, ref ee, aa, bb, X[7], 5);
+ II(ref bb, cc, ref dd, ee, aa, X[15], 6);
+ II(ref aa, bb, ref cc, dd, ee, X[14], 8);
+ II(ref ee, aa, ref bb, cc, dd, X[5], 6);
+ II(ref dd, ee, ref aa, bb, cc, X[6], 5);
+ II(ref cc, dd, ref ee, aa, bb, X[2], 12);
+
+ /* round 5 */
+ JJ(ref bb, cc, ref dd, ee, aa, X[4], 9);
+ JJ(ref aa, bb, ref cc, dd, ee, X[0], 15);
+ JJ(ref ee, aa, ref bb, cc, dd, X[5], 5);
+ JJ(ref dd, ee, ref aa, bb, cc, X[9], 11);
+ JJ(ref cc, dd, ref ee, aa, bb, X[7], 6);
+ JJ(ref bb, cc, ref dd, ee, aa, X[12], 8);
+ JJ(ref aa, bb, ref cc, dd, ee, X[2], 13);
+ JJ(ref ee, aa, ref bb, cc, dd, X[10], 12);
+ JJ(ref dd, ee, ref aa, bb, cc, X[14], 5);
+ JJ(ref cc, dd, ref ee, aa, bb, X[1], 12);
+ JJ(ref bb, cc, ref dd, ee, aa, X[3], 13);
+ JJ(ref aa, bb, ref cc, dd, ee, X[8], 14);
+ JJ(ref ee, aa, ref bb, cc, dd, X[11], 11);
+ JJ(ref dd, ee, ref aa, bb, cc, X[6], 8);
+ JJ(ref cc, dd, ref ee, aa, bb, X[15], 5);
+ JJ(ref bb, cc, ref dd, ee, aa, X[13], 6);
+
+ /* parallel round 1 */
+ JJJ(ref aaa, bbb, ref ccc, ddd, eee, X[5], 8);
+ JJJ(ref eee, aaa, ref bbb, ccc, ddd, X[14], 9);
+ JJJ(ref ddd, eee, ref aaa, bbb, ccc, X[7], 9);
+ JJJ(ref ccc, ddd, ref eee, aaa, bbb, X[0], 11);
+ JJJ(ref bbb, ccc, ref ddd, eee, aaa, X[9], 13);
+ JJJ(ref aaa, bbb, ref ccc, ddd, eee, X[2], 15);
+ JJJ(ref eee, aaa, ref bbb, ccc, ddd, X[11], 15);
+ JJJ(ref ddd, eee, ref aaa, bbb, ccc, X[4], 5);
+ JJJ(ref ccc, ddd, ref eee, aaa, bbb, X[13], 7);
+ JJJ(ref bbb, ccc, ref ddd, eee, aaa, X[6], 7);
+ JJJ(ref aaa, bbb, ref ccc, ddd, eee, X[15], 8);
+ JJJ(ref eee, aaa, ref bbb, ccc, ddd, X[8], 11);
+ JJJ(ref ddd, eee, ref aaa, bbb, ccc, X[1], 14);
+ JJJ(ref ccc, ddd, ref eee, aaa, bbb, X[10], 14);
+ JJJ(ref bbb, ccc, ref ddd, eee, aaa, X[3], 12);
+ JJJ(ref aaa, bbb, ref ccc, ddd, eee, X[12], 6);
+
+ /* parallel round 2 */
+ III(ref eee, aaa, ref bbb, ccc, ddd, X[6], 9);
+ III(ref ddd, eee, ref aaa, bbb, ccc, X[11], 13);
+ III(ref ccc, ddd, ref eee, aaa, bbb, X[3], 15);
+ III(ref bbb, ccc, ref ddd, eee, aaa, X[7], 7);
+ III(ref aaa, bbb, ref ccc, ddd, eee, X[0], 12);
+ III(ref eee, aaa, ref bbb, ccc, ddd, X[13], 8);
+ III(ref ddd, eee, ref aaa, bbb, ccc, X[5], 9);
+ III(ref ccc, ddd, ref eee, aaa, bbb, X[10], 11);
+ III(ref bbb, ccc, ref ddd, eee, aaa, X[14], 7);
+ III(ref aaa, bbb, ref ccc, ddd, eee, X[15], 7);
+ III(ref eee, aaa, ref bbb, ccc, ddd, X[8], 12);
+ III(ref ddd, eee, ref aaa, bbb, ccc, X[12], 7);
+ III(ref ccc, ddd, ref eee, aaa, bbb, X[4], 6);
+ III(ref bbb, ccc, ref ddd, eee, aaa, X[9], 15);
+ III(ref aaa, bbb, ref ccc, ddd, eee, X[1], 13);
+ III(ref eee, aaa, ref bbb, ccc, ddd, X[2], 11);
+
+ /* parallel round 3 */
+ HHH(ref ddd, eee, ref aaa, bbb, ccc, X[15], 9);
+ HHH(ref ccc, ddd, ref eee, aaa, bbb, X[5], 7);
+ HHH(ref bbb, ccc, ref ddd, eee, aaa, X[1], 15);
+ HHH(ref aaa, bbb, ref ccc, ddd, eee, X[3], 11);
+ HHH(ref eee, aaa, ref bbb, ccc, ddd, X[7], 8);
+ HHH(ref ddd, eee, ref aaa, bbb, ccc, X[14], 6);
+ HHH(ref ccc, ddd, ref eee, aaa, bbb, X[6], 6);
+ HHH(ref bbb, ccc, ref ddd, eee, aaa, X[9], 14);
+ HHH(ref aaa, bbb, ref ccc, ddd, eee, X[11], 12);
+ HHH(ref eee, aaa, ref bbb, ccc, ddd, X[8], 13);
+ HHH(ref ddd, eee, ref aaa, bbb, ccc, X[12], 5);
+ HHH(ref ccc, ddd, ref eee, aaa, bbb, X[2], 14);
+ HHH(ref bbb, ccc, ref ddd, eee, aaa, X[10], 13);
+ HHH(ref aaa, bbb, ref ccc, ddd, eee, X[0], 13);
+ HHH(ref eee, aaa, ref bbb, ccc, ddd, X[4], 7);
+ HHH(ref ddd, eee, ref aaa, bbb, ccc, X[13], 5);
+
+ /* parallel round 4 */
+ GGG(ref ccc, ddd, ref eee, aaa, bbb, X[8], 15);
+ GGG(ref bbb, ccc, ref ddd, eee, aaa, X[6], 5);
+ GGG(ref aaa, bbb, ref ccc, ddd, eee, X[4], 8);
+ GGG(ref eee, aaa, ref bbb, ccc, ddd, X[1], 11);
+ GGG(ref ddd, eee, ref aaa, bbb, ccc, X[3], 14);
+ GGG(ref ccc, ddd, ref eee, aaa, bbb, X[11], 14);
+ GGG(ref bbb, ccc, ref ddd, eee, aaa, X[15], 6);
+ GGG(ref aaa, bbb, ref ccc, ddd, eee, X[0], 14);
+ GGG(ref eee, aaa, ref bbb, ccc, ddd, X[5], 6);
+ GGG(ref ddd, eee, ref aaa, bbb, ccc, X[12], 9);
+ GGG(ref ccc, ddd, ref eee, aaa, bbb, X[2], 12);
+ GGG(ref bbb, ccc, ref ddd, eee, aaa, X[13], 9);
+ GGG(ref aaa, bbb, ref ccc, ddd, eee, X[9], 12);
+ GGG(ref eee, aaa, ref bbb, ccc, ddd, X[7], 5);
+ GGG(ref ddd, eee, ref aaa, bbb, ccc, X[10], 15);
+ GGG(ref ccc, ddd, ref eee, aaa, bbb, X[14], 8);
+
+ /* parallel round 5 */
+ FFF(ref bbb, ccc, ref ddd, eee, aaa, X[12], 8);
+ FFF(ref aaa, bbb, ref ccc, ddd, eee, X[15], 5);
+ FFF(ref eee, aaa, ref bbb, ccc, ddd, X[10], 12);
+ FFF(ref ddd, eee, ref aaa, bbb, ccc, X[4], 9);
+ FFF(ref ccc, ddd, ref eee, aaa, bbb, X[1], 12);
+ FFF(ref bbb, ccc, ref ddd, eee, aaa, X[5], 5);
+ FFF(ref aaa, bbb, ref ccc, ddd, eee, X[8], 14);
+ FFF(ref eee, aaa, ref bbb, ccc, ddd, X[7], 6);
+ FFF(ref ddd, eee, ref aaa, bbb, ccc, X[6], 8);
+ FFF(ref ccc, ddd, ref eee, aaa, bbb, X[2], 13);
+ FFF(ref bbb, ccc, ref ddd, eee, aaa, X[13], 6);
+ FFF(ref aaa, bbb, ref ccc, ddd, eee, X[14], 5);
+ FFF(ref eee, aaa, ref bbb, ccc, ddd, X[0], 15);
+ FFF(ref ddd, eee, ref aaa, bbb, ccc, X[3], 13);
+ FFF(ref ccc, ddd, ref eee, aaa, bbb, X[9], 11);
+ FFF(ref bbb, ccc, ref ddd, eee, aaa, X[11], 11);
+
+ // combine results */
+ ddd += cc + MDbuf[1]; /* final result for MDbuf[0] */
+ MDbuf[1] = MDbuf[2] + dd + eee;
+ MDbuf[2] = MDbuf[3] + ee + aaa;
+ MDbuf[3] = MDbuf[4] + aa + bbb;
+ MDbuf[4] = MDbuf[0] + bb + ccc;
+ MDbuf[0] = ddd;
+ }
+
+ static public void MDfinish(ref UInt32[] MDbuf, byte[] strptr, long index, UInt32 lswlen, UInt32 mswlen)
+ {
+ //UInt32 i; /* counter */
+ var X = Enumerable.Repeat((UInt32)0, 16).ToArray(); /* message words */
+
+
+ /* put bytes from strptr into X */
+ for (var i = 0; i < (lswlen & 63); i++)
+ {
+ /* byte i goes into word X[i div 4] at pos. 8*(i mod 4) */
+ X[i >> 2] ^= Convert.ToUInt32(strptr[i + index]) << (8 * (i & 3));
+ }
+
+ /* append the bit m_n == 1 */
+ X[(lswlen >> 2) & 15] ^= (UInt32)1 << Convert.ToInt32(8 * (lswlen & 3) + 7);
+
+ if ((lswlen & 63) > 55)
+ {
+ /* length goes to next block */
+ compress(ref MDbuf, X);
+ X = Enumerable.Repeat((UInt32)0, 16).ToArray();
+ }
+
+ /* append length in bits*/
+ X[14] = lswlen << 3;
+ X[15] = (lswlen >> 29) | (mswlen << 3);
+ compress(ref MDbuf, X);
+ }
+
+ static int RMDsize = 160;
+ UInt32 [] MDbuf = new UInt32 [RMDsize / 32];
+ UInt32 [] X = new UInt32[16];
+ byte [] UnhashedBuffer = new byte[64];
+ int UnhashedBufferLength = 0;
+ long HashedLength = 0;
+
+ public RIPEMD160Managed()
+ {
+ Initialize();
+ }
+
+ protected override void HashCore (byte[] array, int ibStart, int cbSize)
+ {
+ var index = 0;
+ while(index < cbSize)
+ {
+ var bytesRemaining = cbSize - index;
+ if(UnhashedBufferLength > 0)
+ {
+ if((bytesRemaining + UnhashedBufferLength) >= (UnhashedBuffer.Length))
+ {
+ Array.Copy(array, ibStart + index, UnhashedBuffer, UnhashedBufferLength, (UnhashedBuffer.Length) - UnhashedBufferLength);
+ index += (UnhashedBuffer.Length) - UnhashedBufferLength;
+ UnhashedBufferLength = UnhashedBuffer.Length;
+
+ for (var i = 0; i < 16; i++)
+ X[i] = ReadUInt32(UnhashedBuffer, i * 4);
+
+ compress(ref MDbuf, X);
+ UnhashedBufferLength = 0;
+ }
+ else
+ {
+ Array.Copy(array, ibStart + index, UnhashedBuffer, UnhashedBufferLength, bytesRemaining);
+ UnhashedBufferLength += bytesRemaining;
+ index += bytesRemaining;
+ }
+ }
+ else
+ {
+ if(bytesRemaining >= (UnhashedBuffer.Length))
+ {
+ for (var i = 0; i < 16; i++)
+ X[i] = ReadUInt32(array, index + (i * 4));
+ index += UnhashedBuffer.Length;
+
+ compress(ref MDbuf, X);
+ }
+ else
+ {
+ Array.Copy(array, ibStart + index, UnhashedBuffer, 0, bytesRemaining);
+ UnhashedBufferLength = bytesRemaining;
+ index += bytesRemaining;
+ }
+ }
+ }
+
+ HashedLength += cbSize;
+ }
+
+ protected override byte[] HashFinal ()
+ {
+ MDfinish(ref MDbuf, UnhashedBuffer, 0, Convert.ToUInt32(HashedLength), 0);
+
+ var result = new byte [RMDsize / 8];
+
+ for (var i = 0; i < RMDsize / 8; i += 4)
+ {
+ result[i] = Convert.ToByte(MDbuf[i >> 2] & 0xFF); /* implicit cast to byte */
+ result[i + 1] = Convert.ToByte((MDbuf[i >> 2] >> 8) & 0xFF); /* extracts the 8 least */
+ result[i + 2] = Convert.ToByte((MDbuf[i >> 2] >> 16) & 0xFF); /* significant bits. */
+ result[i + 3] = Convert.ToByte((MDbuf[i >> 2] >> 24) & 0xFF);
+ }
+
+ return result;
+ }
+
+ public override void Initialize ()
+ {
+ MDinit(ref MDbuf);
+ X = Enumerable.Repeat((UInt32)0, 16).ToArray();
+ HashedLength = 0;
+ UnhashedBufferLength = 0;
+ }
+ }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/RIPEMD-160/RIPEMD160Managed.cs.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/RIPEMD-160/RIPEMD160Managed.cs.meta
new file mode 100644
index 0000000..66a0570
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/RIPEMD-160/RIPEMD160Managed.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 26bcc4f1c6c841829281644666d97924
+timeCreated: 1709898527
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/RIPEMD-160/RipemdEncryptionOptions.cs b/DevsDaddy/Shared/CryptoLibrary/Modules/RIPEMD-160/RipemdEncryptionOptions.cs
new file mode 100644
index 0000000..df36007
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/RIPEMD-160/RipemdEncryptionOptions.cs
@@ -0,0 +1,11 @@
+using System.Text;
+using DevsDaddy.Shared.CryptoLibrary.Core;
+
+namespace DevsDaddy.Shared.CryptoLibrary.Modules.RIPEMD_160
+{
+ [System.Serializable]
+ public class RipemdEncryptionOptions : IProviderOptions
+ {
+ public Encoding encoding = Encoding.UTF8;
+ }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/RIPEMD-160/RipemdEncryptionOptions.cs.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/RIPEMD-160/RipemdEncryptionOptions.cs.meta
new file mode 100644
index 0000000..e152f30
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/RIPEMD-160/RipemdEncryptionOptions.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 74488339489a42cebc569ec7b0afb0ef
+timeCreated: 1709897381
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/RIPEMD-160/RipemdProvider.cs b/DevsDaddy/Shared/CryptoLibrary/Modules/RIPEMD-160/RipemdProvider.cs
new file mode 100644
index 0000000..9b41157
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/RIPEMD-160/RipemdProvider.cs
@@ -0,0 +1,65 @@
+using System;
+using DevsDaddy.Shared.CryptoLibrary.Core;
+
+namespace DevsDaddy.Shared.CryptoLibrary.Modules.RIPEMD_160
+{
+ ///
+ /// Old RIPEMD-160 Hashing Provider
+ ///
+ public class RipemdProvider : ICryptoProvider
+ {
+ // Provider Options
+ private RipemdEncryptionOptions _options;
+
+ ///
+ /// RIPEMD-160 Provider
+ ///
+ ///
+ public RipemdProvider(RipemdEncryptionOptions options = null) {
+ _options = options ?? new RipemdEncryptionOptions();
+ }
+
+ ///
+ /// Decrypt String (Not Supported for hashing)
+ ///
+ ///
+ ///
+ ///
+ public string DecryptString(string encryptedString) {
+ throw new Exception($"Failed to decrypt text, because {this.GetType()} doesn't support decryption.");
+ }
+
+ ///
+ /// Decrypt Binary (Not Supported for hashing)
+ ///
+ ///
+ ///
+ ///
+ public byte[] DecryptBinary(byte[] encryptedBinary) {
+ throw new Exception($"Failed to decrypt text, because {this.GetType()} doesn't support decryption.");
+ }
+
+ ///
+ /// Get RIPEMD-160 Hash from String
+ ///
+ ///
+ ///
+ public string EncryptString(string decryptedString) {
+ byte[] encrypted = EncryptBinary(_options.encoding.GetBytes(decryptedString));
+ return Convert.ToBase64String(encrypted);
+ }
+
+ ///
+ /// Get RIPEMD-160 Hash from Byte Array
+ ///
+ ///
+ ///
+ public byte[] EncryptBinary(byte[] decryptedBinary) {
+ using (RIPEMD160 r160 = RIPEMD160.Create())
+ {
+ byte[] hashBytes = r160.ComputeHash(decryptedBinary);
+ return hashBytes;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/RIPEMD-160/RipemdProvider.cs.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/RIPEMD-160/RipemdProvider.cs.meta
new file mode 100644
index 0000000..fa07ede
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/RIPEMD-160/RipemdProvider.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 471108039962485781b7fb6befbd1009
+timeCreated: 1709897391
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/RSA.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/RSA.meta
new file mode 100644
index 0000000..f474689
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/RSA.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 866a055b07f84eacaee1ae7b40aa148e
+timeCreated: 1709889644
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/RSA/RSAEncryptionOptions.cs b/DevsDaddy/Shared/CryptoLibrary/Modules/RSA/RSAEncryptionOptions.cs
new file mode 100644
index 0000000..6376467
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/RSA/RSAEncryptionOptions.cs
@@ -0,0 +1,14 @@
+using System.Text;
+using DevsDaddy.Shared.CryptoLibrary.Core;
+
+namespace DevsDaddy.Shared.CryptoLibrary.Modules.RSA
+{
+ [System.Serializable]
+ public class RSAEncryptionOptions : IProviderOptions
+ {
+ public string publicKey = "RSAPublicKey";
+ public string privateKey = "RSAPrivateKey";
+
+ public Encoding encoding = Encoding.UTF8;
+ }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/RSA/RSAEncryptionOptions.cs.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/RSA/RSAEncryptionOptions.cs.meta
new file mode 100644
index 0000000..a845987
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/RSA/RSAEncryptionOptions.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: ee37ae4cb385462d96af708da83eadfa
+timeCreated: 1709894551
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/RSA/RSAProvider.cs b/DevsDaddy/Shared/CryptoLibrary/Modules/RSA/RSAProvider.cs
new file mode 100644
index 0000000..11259fa
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/RSA/RSAProvider.cs
@@ -0,0 +1,86 @@
+using System;
+using System.Collections.Generic;
+using System.Security.Cryptography;
+using DevsDaddy.Shared.CryptoLibrary.Core;
+
+namespace DevsDaddy.Shared.CryptoLibrary.Modules.RSA
+{
+ ///
+ /// RSA Encryption Provider
+ /// Using for encrypt/decrypt plain text or byte arrays
+ ///
+ public class RSAProvider : ICryptoProvider
+ {
+ // Provider Options
+ private RSAEncryptionOptions _options;
+
+ ///
+ /// RSA Encryption Provider
+ ///
+ ///
+ public RSAProvider(RSAEncryptionOptions options = null) {
+ _options = options ?? new RSAEncryptionOptions();
+ }
+
+ ///
+ /// Decrypt RSA-encrypted string
+ ///
+ ///
+ ///
+ public string DecryptString(string encryptedString) {
+ byte[] decrypted = DecryptBinary(Convert.FromBase64String(encryptedString));
+ return _options.encoding.GetString(decrypted);
+ }
+
+ ///
+ /// Decrypt RSA-encrypted byte array
+ ///
+ ///
+ ///
+ public byte[] DecryptBinary(byte[] encryptedBinary) {
+ using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
+ {
+ rsa.FromXmlString(_options.privateKey);
+ byte[] decrypted = rsa.Decrypt(encryptedBinary, false);
+ return decrypted;
+ }
+ }
+
+ ///
+ /// Encrypt plain-text to RSA-encrypted string
+ ///
+ ///
+ ///
+ public string EncryptString(string decryptedString) {
+ byte[] encrypted = EncryptBinary(_options.encoding.GetBytes(decryptedString));
+ return Convert.ToBase64String(encrypted);
+ }
+
+ ///
+ /// Encrypt byte array to RSA-encrypted byte array
+ ///
+ ///
+ ///
+ public byte[] EncryptBinary(byte[] decryptedBinary) {
+ using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
+ {
+ rsa.FromXmlString(_options.publicKey);
+ byte[] encrypted = rsa.Encrypt(decryptedBinary, false);
+ return encrypted;
+ }
+ }
+
+ ///
+ /// Generate Key Pair for RSA Provider
+ ///
+ ///
+ ///
+ public static KeyValuePair GenerateKeyPair(int keySize)
+ {
+ RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(keySize);
+ string publicKey = rsa.ToXmlString(false);
+ string privateKey = rsa.ToXmlString(true);
+ return new KeyValuePair(publicKey, privateKey);
+ }
+ }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/RSA/RSAProvider.cs.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/RSA/RSAProvider.cs.meta
new file mode 100644
index 0000000..5b92630
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/RSA/RSAProvider.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 5d97d6eae2424e81b81c16663bc8b7c0
+timeCreated: 1709894581
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/SHA.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/SHA.meta
new file mode 100644
index 0000000..fcb9996
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/SHA.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 04b40f7dc243443aa26ffe21731de7f3
+timeCreated: 1709889629
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/SHA/SHA1Provider.cs b/DevsDaddy/Shared/CryptoLibrary/Modules/SHA/SHA1Provider.cs
new file mode 100644
index 0000000..bbc2cfe
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/SHA/SHA1Provider.cs
@@ -0,0 +1,77 @@
+using System;
+using System.Security.Cryptography;
+using System.Text;
+using DevsDaddy.Shared.CryptoLibrary.Core;
+
+namespace DevsDaddy.Shared.CryptoLibrary.Modules.SHA
+{
+ ///
+ /// SHA1 Hashing Provider
+ ///
+ public class SHA1Provider : ICryptoProvider
+ {
+ private SHAEncryptionOptions _options;
+
+ ///
+ /// SHA1 Provider
+ ///
+ ///
+ public SHA1Provider(SHAEncryptionOptions options = null) {
+ _options = options ?? new SHAEncryptionOptions();
+ }
+
+ ///
+ /// Decrypt plain-text (Not Supported for Hashing)
+ ///
+ ///
+ ///
+ ///
+ public string DecryptString(string encryptedString) {
+ throw new Exception($"Failed to decrypt text, because {this.GetType()} doesn't support decryption.");
+ }
+
+ ///
+ /// Decrypt Binary Data (Not Supported for Hashing)
+ ///
+ ///
+ ///
+ ///
+ public byte[] DecryptBinary(byte[] encryptedBinary) {
+ throw new Exception($"Failed to decrypt text, because {this.GetType()} doesn't support decryption.");
+ }
+
+ ///
+ /// Get SHA1 Hash for Plain-text
+ ///
+ ///
+ ///
+ public string EncryptString(string decryptedString) {
+ using (SHA1Managed sha1 = new SHA1Managed())
+ {
+ var hash = sha1.ComputeHash(_options.encoding.GetBytes(decryptedString));
+ var sb = new StringBuilder(hash.Length * 2);
+
+ foreach (byte b in hash)
+ {
+ // can be "x2" if you want lowercase
+ sb.Append(b.ToString("X2"));
+ }
+
+ return sb.ToString();
+ }
+ }
+
+ ///
+ /// Get SHA1 Hash for Byte array
+ ///
+ ///
+ ///
+ public byte[] EncryptBinary(byte[] decryptedBinary) {
+ using (SHA1Managed sha1 = new SHA1Managed())
+ {
+ var hash = sha1.ComputeHash(decryptedBinary);
+ return hash;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/SHA/SHA1Provider.cs.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/SHA/SHA1Provider.cs.meta
new file mode 100644
index 0000000..326ea04
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/SHA/SHA1Provider.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 6d4c9e5dd260446583ebdff39bc31329
+timeCreated: 1709895806
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/SHA/SHA256Provider.cs b/DevsDaddy/Shared/CryptoLibrary/Modules/SHA/SHA256Provider.cs
new file mode 100644
index 0000000..1ea7cc5
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/SHA/SHA256Provider.cs
@@ -0,0 +1,77 @@
+using System;
+using System.Security.Cryptography;
+using System.Text;
+using DevsDaddy.Shared.CryptoLibrary.Core;
+
+namespace DevsDaddy.Shared.CryptoLibrary.Modules.SHA
+{
+ ///
+ /// SHA1 Hashing Provider
+ ///
+ public class SHA256Provider : ICryptoProvider
+ {
+ private SHAEncryptionOptions _options;
+
+ ///
+ /// SHA256 Provider
+ ///
+ ///
+ public SHA256Provider(SHAEncryptionOptions options = null) {
+ _options = options ?? new SHAEncryptionOptions();
+ }
+
+ ///
+ /// Decrypt plain-text (Not Supported for Hashing)
+ ///
+ ///
+ ///
+ ///
+ public string DecryptString(string encryptedString) {
+ throw new Exception($"Failed to decrypt text, because {this.GetType()} doesn't support decryption.");
+ }
+
+ ///
+ /// Decrypt Binary Data (Not Supported for Hashing)
+ ///
+ ///
+ ///
+ ///
+ public byte[] DecryptBinary(byte[] encryptedBinary) {
+ throw new Exception($"Failed to decrypt text, because {this.GetType()} doesn't support decryption.");
+ }
+
+ ///
+ /// Get SHA256 Hash for Plain-text
+ ///
+ ///
+ ///
+ public string EncryptString(string decryptedString) {
+ using (SHA256Managed sha256 = new SHA256Managed())
+ {
+ var hash = sha256.ComputeHash(_options.encoding.GetBytes(decryptedString));
+ var sb = new StringBuilder(hash.Length * 2);
+
+ foreach (byte b in hash)
+ {
+ // can be "x2" if you want lowercase
+ sb.Append(b.ToString("X2"));
+ }
+
+ return sb.ToString();
+ }
+ }
+
+ ///
+ /// Get SHA256 Hash for Byte array
+ ///
+ ///
+ ///
+ public byte[] EncryptBinary(byte[] decryptedBinary) {
+ using (SHA256Managed sha256 = new SHA256Managed())
+ {
+ var hash = sha256.ComputeHash(decryptedBinary);
+ return hash;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/SHA/SHA256Provider.cs.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/SHA/SHA256Provider.cs.meta
new file mode 100644
index 0000000..efc00c9
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/SHA/SHA256Provider.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: cb92a95f816c49599c5f2b4ee4d38422
+timeCreated: 1709895861
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/SHA/SHA512Provider.cs b/DevsDaddy/Shared/CryptoLibrary/Modules/SHA/SHA512Provider.cs
new file mode 100644
index 0000000..86ad58f
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/SHA/SHA512Provider.cs
@@ -0,0 +1,77 @@
+using System;
+using System.Security.Cryptography;
+using System.Text;
+using DevsDaddy.Shared.CryptoLibrary.Core;
+
+namespace DevsDaddy.Shared.CryptoLibrary.Modules.SHA
+{
+ ///
+ /// SHA512 Hashing Provider
+ ///
+ public class SHA512Provider : ICryptoProvider
+ {
+ private SHAEncryptionOptions _options;
+
+ ///
+ /// SHA512 Provider
+ ///
+ ///
+ public SHA512Provider(SHAEncryptionOptions options = null) {
+ _options = options ?? new SHAEncryptionOptions();
+ }
+
+ ///
+ /// Decrypt plain-text (Not Supported for Hashing)
+ ///
+ ///
+ ///
+ ///
+ public string DecryptString(string encryptedString) {
+ throw new Exception($"Failed to decrypt text, because {this.GetType()} doesn't support decryption.");
+ }
+
+ ///
+ /// Decrypt Binary Data (Not Supported for Hashing)
+ ///
+ ///
+ ///
+ ///
+ public byte[] DecryptBinary(byte[] encryptedBinary) {
+ throw new Exception($"Failed to decrypt text, because {this.GetType()} doesn't support decryption.");
+ }
+
+ ///
+ /// Get SHA512 Hash for Plain-text
+ ///
+ ///
+ ///
+ public string EncryptString(string decryptedString) {
+ using (SHA512Managed sha256 = new SHA512Managed())
+ {
+ var hash = sha256.ComputeHash(_options.encoding.GetBytes(decryptedString));
+ var sb = new StringBuilder(hash.Length * 2);
+
+ foreach (byte b in hash)
+ {
+ // can be "x2" if you want lowercase
+ sb.Append(b.ToString("X2"));
+ }
+
+ return sb.ToString();
+ }
+ }
+
+ ///
+ /// Get SHA512 Hash for Byte array
+ ///
+ ///
+ ///
+ public byte[] EncryptBinary(byte[] decryptedBinary) {
+ using (SHA512Managed sha512 = new SHA512Managed())
+ {
+ var hash = sha512.ComputeHash(decryptedBinary);
+ return hash;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/SHA/SHA512Provider.cs.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/SHA/SHA512Provider.cs.meta
new file mode 100644
index 0000000..2ca78e8
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/SHA/SHA512Provider.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 2164e47f6c7a4874b422c7789539ec18
+timeCreated: 1709895868
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/SHA/SHAEncryptionOptions.cs b/DevsDaddy/Shared/CryptoLibrary/Modules/SHA/SHAEncryptionOptions.cs
new file mode 100644
index 0000000..4a794bf
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/SHA/SHAEncryptionOptions.cs
@@ -0,0 +1,11 @@
+using System.Text;
+using DevsDaddy.Shared.CryptoLibrary.Core;
+
+namespace DevsDaddy.Shared.CryptoLibrary.Modules.SHA
+{
+ [System.Serializable]
+ public class SHAEncryptionOptions : IProviderOptions
+ {
+ public Encoding encoding = Encoding.UTF8;
+ }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/SHA/SHAEncryptionOptions.cs.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/SHA/SHAEncryptionOptions.cs.meta
new file mode 100644
index 0000000..38614c2
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/SHA/SHAEncryptionOptions.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 329c2b00898a419ebd3501427a96764f
+timeCreated: 1709895780
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/TripleDES.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/TripleDES.meta
new file mode 100644
index 0000000..1b0a6c7
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/TripleDES.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: aac9be5c0d2c4e468ce9d2fe00d89460
+timeCreated: 1709896341
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/TripleDES/TripleDESEncryptionOptions.cs b/DevsDaddy/Shared/CryptoLibrary/Modules/TripleDES/TripleDESEncryptionOptions.cs
new file mode 100644
index 0000000..1ddece4
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/TripleDES/TripleDESEncryptionOptions.cs
@@ -0,0 +1,16 @@
+using System.Security.Cryptography;
+using System.Text;
+using DevsDaddy.Shared.CryptoLibrary.Core;
+
+namespace DevsDaddy.Shared.CryptoLibrary.Modules.TripleDES
+{
+ [System.Serializable]
+ public class TripleDESEncryptionOptions : IProviderOptions
+ {
+ public string cryptoKey = "ABCDEFGH";
+ public Encoding encoding = Encoding.UTF8;
+
+ public CipherMode mode = CipherMode.ECB;
+ public PaddingMode padding = PaddingMode.PKCS7;
+ }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/TripleDES/TripleDESEncryptionOptions.cs.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/TripleDES/TripleDESEncryptionOptions.cs.meta
new file mode 100644
index 0000000..38f0e6d
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/TripleDES/TripleDESEncryptionOptions.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 5454f018e8874bc88dae375a8e20f892
+timeCreated: 1709896365
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/TripleDES/TripleDESProvider.cs b/DevsDaddy/Shared/CryptoLibrary/Modules/TripleDES/TripleDESProvider.cs
new file mode 100644
index 0000000..5b82f69
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/TripleDES/TripleDESProvider.cs
@@ -0,0 +1,87 @@
+using System;
+using System.Security.Cryptography;
+using DevsDaddy.Shared.CryptoLibrary.Core;
+
+namespace DevsDaddy.Shared.CryptoLibrary.Modules.TripleDES
+{
+ ///
+ /// Triple DES Modern Crypto Provider
+ ///
+ public class TripleDESProvider : ICryptoProvider
+ {
+ private TripleDESEncryptionOptions _options;
+
+ ///
+ /// Triple DES Provider
+ ///
+ ///
+ public TripleDESProvider(TripleDESEncryptionOptions options = null) {
+ _options = options ?? new TripleDESEncryptionOptions();
+ }
+
+ ///
+ /// Decrypt plain-text using Triple DES
+ ///
+ ///
+ ///
+ public string DecryptString(string encryptedString) {
+ byte[] txtByteData = Convert.FromBase64String(encryptedString);
+ byte[] decoded = DecryptBinary(txtByteData);
+ return _options.encoding.GetString(decoded);
+ }
+
+ ///
+ /// Decrypt byte array using Triple DES
+ ///
+ ///
+ ///
+ public byte[] DecryptBinary(byte[] encryptedBinary) {
+ MD5CryptoServiceProvider MD5CryptoService = new MD5CryptoServiceProvider();
+ byte[] securityKeyArray = MD5CryptoService.ComputeHash(_options.encoding.GetBytes(_options.cryptoKey));
+ MD5CryptoService.Clear();
+
+ var tripleDESCryptoService = new TripleDESCryptoServiceProvider();
+ tripleDESCryptoService.Key = securityKeyArray;
+ tripleDESCryptoService.Mode = _options.mode;
+ tripleDESCryptoService.Padding = _options.padding;
+
+ var crytpoTransform = tripleDESCryptoService.CreateDecryptor();
+ byte[] resultArray = crytpoTransform.TransformFinalBlock(encryptedBinary, 0, encryptedBinary.Length);
+ tripleDESCryptoService.Clear();
+ return resultArray;
+ }
+
+ ///
+ /// Encrypt Plain-Text using Triple DES
+ ///
+ ///
+ ///
+ public string EncryptString(string decryptedString) {
+ byte[] txtByteData = _options.encoding.GetBytes(decryptedString);
+ byte[] encoded = EncryptBinary(txtByteData);
+ return Convert.ToBase64String(encoded);
+ }
+
+ ///
+ /// Encrypt Byte Array using Triple DES
+ ///
+ ///
+ ///
+ public byte[] EncryptBinary(byte[] decryptedBinary) {
+ MD5CryptoServiceProvider MD5CryptoService = new MD5CryptoServiceProvider();
+ byte[] securityKeyArray = MD5CryptoService.ComputeHash(_options.encoding.GetBytes(_options.cryptoKey));
+ MD5CryptoService.Clear();
+
+ var tripleDESCryptoService = new TripleDESCryptoServiceProvider();
+ tripleDESCryptoService.Key = securityKeyArray;
+ tripleDESCryptoService.Mode = _options.mode;
+ tripleDESCryptoService.Padding = _options.padding;
+
+ var crytpoTransform = tripleDESCryptoService.CreateEncryptor();
+ byte[] resultArray = crytpoTransform.TransformFinalBlock(decryptedBinary, 0, decryptedBinary.Length);
+
+ tripleDESCryptoService.Clear();
+ return resultArray;
+ }
+ }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/TripleDES/TripleDESProvider.cs.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/TripleDES/TripleDESProvider.cs.meta
new file mode 100644
index 0000000..05daaea
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/TripleDES/TripleDESProvider.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: d899fe1793c34e3984a69625da66e8be
+timeCreated: 1709896382
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/Twofish.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/Twofish.meta
new file mode 100644
index 0000000..9fe2912
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/Twofish.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 533b53f6351c40b0a209b008dc6facaf
+timeCreated: 1709897320
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/Twofish/Twofish.cs b/DevsDaddy/Shared/CryptoLibrary/Modules/Twofish/Twofish.cs
new file mode 100644
index 0000000..33635e1
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/Twofish/Twofish.cs
@@ -0,0 +1,749 @@
+using System;
+using System.Runtime.CompilerServices;
+using System.Security.Cryptography;
+
+namespace DevsDaddy.Shared.CryptoLibrary.Modules.Twofish
+{
+ public sealed class Twofish : SymmetricAlgorithm
+ {
+ public Twofish() : base() {
+ KeySizeValue = KeySizeInBits;
+ BlockSizeValue = BlockSizeInBits;
+ FeedbackSizeValue = BlockSizeValue;
+ LegalBlockSizesValue = new KeySizes[] { new KeySizes(BlockSizeInBits, BlockSizeInBits, 0) };
+ LegalKeySizesValue = new KeySizes[] { new KeySizes(128, 256, 64) }; // 128, 192, or 256
+
+ base.Mode = CipherMode.CBC; // same as default
+ base.Padding = PaddingMode.PKCS7;
+ }
+
+ public override ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[]? rgbIV) {
+ if (rgbKey == null) { throw new ArgumentNullException(nameof(rgbKey), "Key cannot be null."); }
+ if (rgbKey.Length != KeySize / 8) { throw new ArgumentOutOfRangeException(nameof(rgbKey), "Key size mismatch."); }
+ if (Mode == CipherMode.CBC) {
+ if (rgbIV == null) { throw new ArgumentNullException(nameof(rgbIV), "IV cannot be null."); }
+ if (rgbIV.Length != 16) { throw new ArgumentOutOfRangeException(nameof(rgbIV), "Invalid IV size."); }
+ }
+
+ return new TwofishTransform(rgbKey, rgbIV, TwofishTransformMode.Decrypt, Mode, Padding);
+ }
+
+ public override ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[]? rgbIV) {
+ if (rgbKey == null) { throw new ArgumentNullException(nameof(rgbKey), "Key cannot be null."); }
+ if (rgbKey.Length != KeySize / 8) { throw new ArgumentOutOfRangeException(nameof(rgbKey), "Key size mismatch."); }
+ if (Mode == CipherMode.CBC) {
+ if (rgbIV == null) { throw new ArgumentNullException(nameof(rgbIV), "IV cannot be null."); }
+ if (rgbIV.Length != 16) { throw new ArgumentOutOfRangeException(nameof(rgbIV), "Invalid IV size."); }
+ }
+
+ return new TwofishTransform(rgbKey, rgbIV, TwofishTransformMode.Encrypt, Mode, Padding);
+ }
+
+ public override void GenerateIV() {
+ byte[] rndKey = new byte[FeedbackSizeValue / 8];
+ RandomNumberGenerator generator = RandomNumberGenerator.Create();
+ generator.GetBytes(rndKey);
+ IVValue = rndKey;
+ }
+
+ public override void GenerateKey() {
+ byte[] rndKey = new byte[KeySizeValue / 8];
+ RandomNumberGenerator generator = RandomNumberGenerator.Create();
+ generator.GetBytes(rndKey);
+ KeyValue = rndKey;
+ }
+
+ public override CipherMode Mode {
+ get { return base.Mode; }
+ set {
+ switch (value) {
+ case CipherMode.CBC: break;
+#pragma warning disable CA5358 // While using ECB is not recommended, it's still supported
+ case CipherMode.ECB: break;
+#pragma warning restore CA5358 // Review cipher mode usage with cryptography experts
+ default: throw new CryptographicException("Cipher mode is not supported.");
+ }
+ base.Mode = value;
+ }
+ }
+
+ public override PaddingMode Padding {
+ get { return base.Padding; }
+ set {
+ base.Padding = value switch {
+ PaddingMode.None => value,
+ PaddingMode.PKCS7 => value,
+ PaddingMode.Zeros => value,
+ PaddingMode.ANSIX923 => value,
+ PaddingMode.ISO10126 => value,
+ _ => throw new CryptographicException("Padding mode is not supported."),
+ };
+ }
+ }
+
+ private const int KeySizeInBits = 256;
+ private const int BlockSizeInBits = 128;
+ }
+
+ enum TwofishTransformMode {
+ Encrypt = 0,
+ Decrypt = 1
+ }
+
+ sealed class TwofishTransform : ICryptoTransform
+ {
+ internal TwofishTransform(byte[] rgbKey, byte[]? rgbIV, TwofishTransformMode transformMode, CipherMode cipherMode, PaddingMode paddingMode) {
+ if (rgbKey == null) { throw new ArgumentNullException(nameof(rgbKey), "Key cannot be null."); }
+ if (rgbKey.Length is not 16 and not 24 and not 32) { throw new ArgumentOutOfRangeException(nameof(rgbKey), "Key must be 128, 192, or 256 bits."); }
+ if ((rgbIV is not null) && (rgbIV.Length != 16)) { throw new ArgumentOutOfRangeException(nameof(rgbKey), "IV must be 128 bits."); }
+ CipherMode = cipherMode;
+ TransformMode = transformMode;
+ PaddingMode = paddingMode;
+
+ DecryptionBuffer = new byte[16];
+
+ Key = new DWord[rgbKey.Length / 4];
+ SBoxKeys = new DWord[MaxKeyBits / 64];
+ SubKeys = new DWord[TotalSubkeys];
+
+ var key32 = new uint[Key.Length];
+ Buffer.BlockCopy(rgbKey, 0, key32, 0, rgbKey.Length);
+ for (var i = 0; i < Key.Length; i++) { Key[i] = (DWord)key32[i]; }
+ Array.Clear(key32, 0, key32.Length);
+
+ if (rgbIV != null) {
+ IV = new DWord[rgbIV.Length];
+ var iv32 = new uint[IV.Length];
+ Buffer.BlockCopy(rgbIV, 0, iv32, 0, rgbIV.Length);
+ for (var i = 0; i < IV.Length; i++) { IV[i] = (DWord)iv32[i]; }
+ Array.Clear(iv32, 0, iv32.Length);
+ }
+
+ ReKey();
+ }
+
+ private readonly TwofishTransformMode TransformMode;
+ private readonly CipherMode CipherMode;
+ private readonly PaddingMode PaddingMode;
+
+ ///
+ /// Gets a value indicating whether the current transform can be reused.
+ ///
+ public bool CanReuseTransform { get { return false; } }
+
+ ///
+ /// Gets a value indicating whether multiple blocks can be transformed.
+ ///
+ public bool CanTransformMultipleBlocks { get { return true; } }
+
+ ///
+ /// Gets the input block size (in bytes).
+ ///
+ public int InputBlockSize { get { return 16; } } //block is always 128 bits
+
+ ///
+ /// Gets the output block size (in bytes).
+ ///
+ public int OutputBlockSize { get { return 16; } } //block is always 128 bits
+
+ ///
+ /// Releases resources.
+ ///
+ public void Dispose() {
+ Dispose(true);
+ }
+
+ private void Dispose(bool disposing) {
+ if (disposing) {
+ Array.Clear(Key, 0, Key.Length);
+ if (IV != null) { Array.Clear(IV, 0, IV.Length); }
+ Array.Clear(SBoxKeys, 0, SBoxKeys.Length);
+ Array.Clear(SubKeys, 0, SubKeys.Length);
+ Array.Clear(DecryptionBuffer, 0, DecryptionBuffer.Length);
+ }
+ }
+
+ public int TransformBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset) {
+ if (inputBuffer == null) { throw new ArgumentNullException(nameof(inputBuffer), "Input buffer cannot be null."); }
+ if (outputBuffer == null) { throw new ArgumentNullException(nameof(outputBuffer), "Output buffer cannot be null."); }
+ if (inputOffset < 0) { throw new ArgumentOutOfRangeException(nameof(inputOffset), "Input offset must be non-negative number."); }
+ if (outputOffset < 0) { throw new ArgumentOutOfRangeException(nameof(outputOffset), "Output offset must be non-negative number."); }
+ if ((inputCount <= 0) || (inputCount % 16 != 0) || (inputCount > inputBuffer.Length)) { throw new ArgumentOutOfRangeException(nameof(inputCount), "Invalid input count."); }
+ if ((inputBuffer.Length - inputCount) < inputOffset) { throw new ArgumentOutOfRangeException(nameof(inputCount), "Invalid input length."); }
+ if (outputOffset + inputCount > outputBuffer.Length) { throw new ArgumentOutOfRangeException(nameof(outputOffset), "Insufficient output buffer."); }
+
+ if (TransformMode == TwofishTransformMode.Encrypt) {
+
+ for (var i = 0; i < inputCount; i += 16) {
+ BlockEncrypt(inputBuffer, inputOffset + i, outputBuffer, outputOffset + i);
+ }
+ return inputCount;
+
+ } else { // Decrypt
+
+ var bytesWritten = 0;
+
+ if (DecryptionBufferInUse) { // process the last block of previous round
+ BlockDecrypt(DecryptionBuffer, 0, outputBuffer, outputOffset);
+ DecryptionBufferInUse = false;
+ outputOffset += 16;
+ bytesWritten += 16;
+ }
+
+ for (var i = 0; i < inputCount - 16; i += 16) {
+ BlockDecrypt(inputBuffer, inputOffset + i, outputBuffer, outputOffset);
+ outputOffset += 16;
+ bytesWritten += 16;
+ }
+
+ if (PaddingMode == PaddingMode.None) {
+ BlockDecrypt(inputBuffer, inputOffset + inputCount - 16, outputBuffer, outputOffset);
+ return inputCount;
+ } else { // save last block without processing because decryption otherwise cannot detect padding in CryptoStream
+ Buffer.BlockCopy(inputBuffer, inputOffset + inputCount - 16, DecryptionBuffer, 0, 16);
+ DecryptionBufferInUse = true;
+ }
+
+ return bytesWritten;
+
+ }
+ }
+
+ public byte[] TransformFinalBlock(byte[] inputBuffer, int inputOffset, int inputCount) {
+ if (inputBuffer == null) { throw new ArgumentNullException(nameof(inputBuffer), "Input buffer cannot be null."); }
+ if (inputOffset < 0) { throw new ArgumentOutOfRangeException(nameof(inputOffset), "Input offset must be non-negative number."); }
+ if ((inputCount < 0) || (inputCount > inputBuffer.Length)) { throw new ArgumentOutOfRangeException(nameof(inputCount), "Invalid input count."); }
+ if ((PaddingMode == PaddingMode.None) && (inputCount % 16 != 0)) { throw new ArgumentOutOfRangeException(nameof(inputCount), "No padding for final block."); }
+ if ((inputBuffer.Length - inputCount) < inputOffset) { throw new ArgumentOutOfRangeException(nameof(inputCount), "Invalid input length."); }
+
+ if (TransformMode == TwofishTransformMode.Encrypt) {
+
+ int paddedLength;
+ byte[] paddedInputBuffer;
+ int paddedInputOffset;
+ switch (PaddingMode) {
+ case PaddingMode.None:
+ paddedLength = inputCount;
+ paddedInputBuffer = inputBuffer;
+ paddedInputOffset = inputOffset;
+ break;
+
+ case PaddingMode.PKCS7:
+ paddedLength = inputCount / 16 * 16 + 16; //to round to next whole block
+ paddedInputBuffer = new byte[paddedLength];
+ paddedInputOffset = 0;
+ Buffer.BlockCopy(inputBuffer, inputOffset, paddedInputBuffer, 0, inputCount);
+ var added = (byte)(paddedLength - inputCount);
+ for (var i = inputCount; i < inputCount + added; i++) {
+ paddedInputBuffer[i] = added;
+ }
+ break;
+
+ case PaddingMode.Zeros:
+ paddedLength = (inputCount + 15) / 16 * 16; //to round to next whole block
+ paddedInputBuffer = new byte[paddedLength];
+ paddedInputOffset = 0;
+ Buffer.BlockCopy(inputBuffer, inputOffset, paddedInputBuffer, 0, inputCount);
+ break;
+
+ case PaddingMode.ANSIX923:
+ paddedLength = inputCount / 16 * 16 + 16; //to round to next whole block
+ paddedInputBuffer = new byte[paddedLength];
+ paddedInputOffset = 0;
+ Buffer.BlockCopy(inputBuffer, inputOffset, paddedInputBuffer, 0, inputCount);
+ paddedInputBuffer[^1] = (byte)(paddedLength - inputCount);
+ break;
+
+ case PaddingMode.ISO10126:
+ paddedLength = inputCount / 16 * 16 + 16; //to round to next whole block
+ paddedInputBuffer = new byte[paddedLength];
+ RandomNumberGenerator.Fill(paddedInputBuffer.AsSpan(inputCount));
+ paddedInputOffset = 0;
+ Buffer.BlockCopy(inputBuffer, inputOffset, paddedInputBuffer, 0, inputCount);
+ paddedInputBuffer[^1] = (byte)(paddedLength - inputCount);
+ break;
+
+ default: throw new CryptographicException("Unsupported padding mode.");
+ }
+
+ var outputBuffer = new byte[paddedLength];
+
+ for (var i = 0; i < paddedLength; i += 16) {
+ BlockEncrypt(paddedInputBuffer, paddedInputOffset + i, outputBuffer, i);
+ }
+
+ return outputBuffer;
+
+ } else { // Decrypt
+
+ byte[] outputBuffer;
+
+ if (PaddingMode == PaddingMode.None) {
+ outputBuffer = new byte[inputCount];
+ } else if (inputCount % 16 != 0) {
+ throw new ArgumentOutOfRangeException(nameof(inputCount), "Invalid input count.");
+ } else {
+ outputBuffer = new byte[inputCount + (DecryptionBufferInUse ? 16 : 0)];
+ }
+
+ var outputOffset = 0;
+
+ if (DecryptionBufferInUse) { // process leftover padding buffer to keep CryptoStream happy
+ BlockDecrypt(DecryptionBuffer, 0, outputBuffer, 0);
+ DecryptionBufferInUse = false;
+ outputOffset = 16;
+ }
+
+ for (var i = 0; i < inputCount; i += 16) {
+ BlockDecrypt(inputBuffer, inputOffset + i, outputBuffer, outputOffset + i);
+ }
+
+ return RemovePadding(outputBuffer, PaddingMode);
+
+ }
+ }
+
+ private readonly byte[] DecryptionBuffer;
+ private bool DecryptionBufferInUse;
+
+ private static byte[] RemovePadding(byte[] outputBuffer, PaddingMode paddingMode) {
+ if (paddingMode == PaddingMode.PKCS7) {
+ var padding = outputBuffer[^1];
+ if (padding is < 1 or > 16) { throw new CryptographicException("Invalid padding."); }
+ for (var i = outputBuffer.Length - padding; i < outputBuffer.Length; i++) {
+ if (outputBuffer[i] != padding) { throw new CryptographicException("Invalid padding."); }
+ }
+ var newOutputBuffer = new byte[outputBuffer.Length - padding];
+ Buffer.BlockCopy(outputBuffer, 0, newOutputBuffer, 0, newOutputBuffer.Length);
+ return newOutputBuffer;
+ } else if (paddingMode == PaddingMode.Zeros) {
+ var newOutputLength = outputBuffer.Length;
+ for (var i = outputBuffer.Length - 1; i >= Math.Max(outputBuffer.Length - 16, 0); i--) {
+ if (outputBuffer[i] != 0) {
+ newOutputLength = i + 1;
+ break;
+ }
+ }
+ if (newOutputLength == outputBuffer.Length) {
+ return outputBuffer;
+ } else {
+ var newOutputBuffer = new byte[newOutputLength];
+ Buffer.BlockCopy(outputBuffer, 0, newOutputBuffer, 0, newOutputBuffer.Length);
+ return newOutputBuffer;
+ }
+ } else if (paddingMode == PaddingMode.ANSIX923) {
+ var padding = outputBuffer[^1];
+ if (padding is < 1 or > 16) { throw new CryptographicException("Invalid padding."); }
+ for (var i = outputBuffer.Length - padding; i < outputBuffer.Length - 1; i++) {
+ if (outputBuffer[i] != 0) { throw new CryptographicException("Invalid padding."); }
+ }
+ var newOutputBuffer = new byte[outputBuffer.Length - padding];
+ Buffer.BlockCopy(outputBuffer, 0, newOutputBuffer, 0, newOutputBuffer.Length);
+ return newOutputBuffer;
+ } else if (paddingMode == PaddingMode.ISO10126) {
+ var padding = outputBuffer[^1];
+ if (padding is < 1 or > 16) { throw new CryptographicException("Invalid padding."); }
+ var newOutputBuffer = new byte[outputBuffer.Length - padding];
+ Buffer.BlockCopy(outputBuffer, 0, newOutputBuffer, 0, newOutputBuffer.Length);
+ return newOutputBuffer;
+ } else { // None
+ return outputBuffer;
+ }
+ }
+
+ private const int BlockSize = 128; //number of bits per block
+ private const int Rounds = 16; //default number of rounds for 128/192/256-bit keys
+ private const int MaxKeyBits = 256; //max number of bits of key
+
+ private const int InputWhiten = 0;
+ private const int OutputWhiten = (InputWhiten + BlockSize / 32);
+ private const int RoundSubkeys = (OutputWhiten + BlockSize / 32);
+ private const int TotalSubkeys = (RoundSubkeys + 2 * Rounds);
+
+ private readonly DWord[] Key;
+ private readonly DWord[]? IV;
+ private readonly DWord[] SBoxKeys;
+ private readonly DWord[] SubKeys;
+
+ private const int SubkeyStep = 0x02020202;
+ private const int SubkeyBump = 0x01010101;
+ private const int SubkeyRotateLeft = 9;
+
+ private void ReKey() {
+ BuildMds(); //built only first time it is accessed
+
+ var k32e = new DWord[Key.Length / 2];
+ var k32o = new DWord[Key.Length / 2]; //even/odd key dwords
+
+ var k64Cnt = Key.Length / 2;
+ for (var i = 0; i < k64Cnt; i++) { //split into even/odd key dwords
+ k32e[i] = Key[2 * i];
+ k32o[i] = Key[2 * i + 1];
+ SBoxKeys[k64Cnt - 1 - i] = ReedSolomonMdsEncode(k32e[i], k32o[i]); //compute S-box keys using (12,8) Reed-Solomon code over GF(256)
+ }
+
+ var subkeyCnt = RoundSubkeys + 2 * Rounds;
+ var keyLen = Key.Length * 4 * 8;
+ for (var i = 0; i < subkeyCnt / 2; i++) { //compute round subkeys for PHT
+ var A = F32((DWord)(i * SubkeyStep), k32e, keyLen); //A uses even key dwords
+ var B = F32((DWord)(i * SubkeyStep + SubkeyBump), k32o, keyLen); //B uses odd key dwords
+ B = B.RotateLeft(8);
+ SubKeys[2 * i] = A + B; //combine with a PHT
+ SubKeys[2 * i + 1] = (A + 2 * B).RotateLeft(SubkeyRotateLeft);
+ }
+ }
+
+ internal void BlockEncrypt(byte[] inputBuffer, int inputOffset, byte[] outputBuffer, int outputBufferOffset) {
+ var x = new DWord[BlockSize / 32];
+ for (var i = 0; i < BlockSize / 32; i++) { //copy in the block, add whitening
+ x[i] = new DWord(inputBuffer, inputOffset + i * 4) ^ SubKeys[InputWhiten + i];
+ if ((CipherMode == CipherMode.CBC) && (IV != null)) { x[i] ^= IV[i]; }
+ }
+
+ var keyLen = Key.Length * 4 * 8;
+ for (var r = 0; r < Rounds; r++) { //main Twofish encryption loop
+ var t0 = F32(x[0], SBoxKeys, keyLen);
+ var t1 = F32(x[1].RotateLeft(8), SBoxKeys, keyLen);
+
+ x[3] = x[3].RotateLeft(1);
+ x[2] ^= t0 + t1 + SubKeys[RoundSubkeys + 2 * r]; //PHT, round keys
+ x[3] ^= t0 + 2 * t1 + SubKeys[RoundSubkeys + 2 * r + 1];
+ x[2] = x[2].RotateRight(1);
+
+ if (r < Rounds - 1) { //swap for next round
+ (x[2], x[0]) = (x[0], x[2]);
+ (x[3], x[1]) = (x[1], x[3]);
+ }
+ }
+
+ for (var i = 0; i < BlockSize / 32; i++) { //copy out, with whitening
+ var outValue = x[i] ^ SubKeys[OutputWhiten + i];
+ outputBuffer[outputBufferOffset + i * 4 + 0] = outValue.B0;
+ outputBuffer[outputBufferOffset + i * 4 + 1] = outValue.B1;
+ outputBuffer[outputBufferOffset + i * 4 + 2] = outValue.B2;
+ outputBuffer[outputBufferOffset + i * 4 + 3] = outValue.B3;
+ if ((CipherMode == CipherMode.CBC) && (IV != null)) { IV[i] = outValue; }
+ }
+ }
+
+ internal void BlockDecrypt(byte[] inputBuffer, int inputOffset, byte[] outputBuffer, int outputBufferOffset) {
+ var x = new DWord[BlockSize / 32];
+ var input = new DWord[BlockSize / 32];
+ for (var i = 0; i < BlockSize / 32; i++) { //copy in the block, add whitening
+ input[i] = new DWord(inputBuffer, inputOffset + i * 4);
+ x[i] = input[i] ^ SubKeys[OutputWhiten + i];
+ }
+
+ var keyLen = Key.Length * 4 * 8;
+ for (var r = Rounds - 1; r >= 0; r--) { //main Twofish decryption loop
+ var t0 = F32(x[0], SBoxKeys, keyLen);
+ var t1 = F32(x[1].RotateLeft(8), SBoxKeys, keyLen);
+
+ x[2] = x[2].RotateLeft(1);
+ x[2] ^= t0 + t1 + SubKeys[RoundSubkeys + 2 * r]; //PHT, round keys
+ x[3] ^= t0 + 2 * t1 + SubKeys[RoundSubkeys + 2 * r + 1];
+ x[3] = x[3].RotateRight(1);
+
+ if (r > 0) { //unswap, except for last round
+ t0 = x[0]; x[0] = x[2]; x[2] = t0;
+ t1 = x[1]; x[1] = x[3]; x[3] = t1;
+ }
+ }
+
+ for (var i = 0; i < BlockSize / 32; i++) { //copy out, with whitening
+ x[i] ^= SubKeys[InputWhiten + i];
+ if ((CipherMode == CipherMode.CBC) && (IV != null)) {
+ x[i] ^= IV[i];
+ IV[i] = input[i];
+ }
+ outputBuffer[outputBufferOffset + i * 4 + 0] = x[i].B0;
+ outputBuffer[outputBufferOffset + i * 4 + 1] = x[i].B1;
+ outputBuffer[outputBufferOffset + i * 4 + 2] = x[i].B2;
+ outputBuffer[outputBufferOffset + i * 4 + 3] = x[i].B3;
+ }
+ }
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ private static DWord F32(DWord x, DWord[] k32, int keyLen) {
+ if (keyLen >= 256) {
+ x.B0 = (byte)(P8x8[P_04][x.B0] ^ k32[3].B0);
+ x.B1 = (byte)(P8x8[P_14][x.B1] ^ k32[3].B1);
+ x.B2 = (byte)(P8x8[P_24][x.B2] ^ k32[3].B2);
+ x.B3 = (byte)(P8x8[P_34][x.B3] ^ k32[3].B3);
+ }
+ if (keyLen >= 192) {
+ x.B0 = (byte)(P8x8[P_03][x.B0] ^ k32[2].B0);
+ x.B1 = (byte)(P8x8[P_13][x.B1] ^ k32[2].B1);
+ x.B2 = (byte)(P8x8[P_23][x.B2] ^ k32[2].B2);
+ x.B3 = (byte)(P8x8[P_33][x.B3] ^ k32[2].B3);
+ }
+ if (keyLen >= 128) {
+ x = MdsTable[0][P8x8[P_01][P8x8[P_02][x.B0] ^ k32[1].B0] ^ k32[0].B0]
+ ^ MdsTable[1][P8x8[P_11][P8x8[P_12][x.B1] ^ k32[1].B1] ^ k32[0].B1]
+ ^ MdsTable[2][P8x8[P_21][P8x8[P_22][x.B2] ^ k32[1].B2] ^ k32[0].B2]
+ ^ MdsTable[3][P8x8[P_31][P8x8[P_32][x.B3] ^ k32[1].B3] ^ k32[0].B3];
+ }
+
+ return x;
+ }
+
+ private const uint P_01 = 0;
+ private const uint P_02 = 0;
+ private const uint P_03 = (P_01 ^ 1); // "extend" to larger key sizes
+ private const uint P_04 = 1;
+
+ private const uint P_11 = 0;
+ private const uint P_12 = 1;
+ private const uint P_13 = (P_11 ^ 1);
+ private const uint P_14 = 0;
+
+ private const uint P_21 = 1;
+ private const uint P_22 = 0;
+ private const uint P_23 = (P_21 ^ 1);
+ private const uint P_24 = 0;
+
+ private const uint P_31 = 1;
+ private const uint P_32 = 1;
+ private const uint P_33 = (P_31 ^ 1);
+ private const uint P_34 = 1;
+
+ private static readonly byte[][] P8x8 = new byte[][] {
+ new byte[] {
+ 0xA9, 0x67, 0xB3, 0xE8, 0x04, 0xFD, 0xA3, 0x76,
+ 0x9A, 0x92, 0x80, 0x78, 0xE4, 0xDD, 0xD1, 0x38,
+ 0x0D, 0xC6, 0x35, 0x98, 0x18, 0xF7, 0xEC, 0x6C,
+ 0x43, 0x75, 0x37, 0x26, 0xFA, 0x13, 0x94, 0x48,
+ 0xF2, 0xD0, 0x8B, 0x30, 0x84, 0x54, 0xDF, 0x23,
+ 0x19, 0x5B, 0x3D, 0x59, 0xF3, 0xAE, 0xA2, 0x82,
+ 0x63, 0x01, 0x83, 0x2E, 0xD9, 0x51, 0x9B, 0x7C,
+ 0xA6, 0xEB, 0xA5, 0xBE, 0x16, 0x0C, 0xE3, 0x61,
+ 0xC0, 0x8C, 0x3A, 0xF5, 0x73, 0x2C, 0x25, 0x0B,
+ 0xBB, 0x4E, 0x89, 0x6B, 0x53, 0x6A, 0xB4, 0xF1,
+ 0xE1, 0xE6, 0xBD, 0x45, 0xE2, 0xF4, 0xB6, 0x66,
+ 0xCC, 0x95, 0x03, 0x56, 0xD4, 0x1C, 0x1E, 0xD7,
+ 0xFB, 0xC3, 0x8E, 0xB5, 0xE9, 0xCF, 0xBF, 0xBA,
+ 0xEA, 0x77, 0x39, 0xAF, 0x33, 0xC9, 0x62, 0x71,
+ 0x81, 0x79, 0x09, 0xAD, 0x24, 0xCD, 0xF9, 0xD8,
+ 0xE5, 0xC5, 0xB9, 0x4D, 0x44, 0x08, 0x86, 0xE7,
+ 0xA1, 0x1D, 0xAA, 0xED, 0x06, 0x70, 0xB2, 0xD2,
+ 0x41, 0x7B, 0xA0, 0x11, 0x31, 0xC2, 0x27, 0x90,
+ 0x20, 0xF6, 0x60, 0xFF, 0x96, 0x5C, 0xB1, 0xAB,
+ 0x9E, 0x9C, 0x52, 0x1B, 0x5F, 0x93, 0x0A, 0xEF,
+ 0x91, 0x85, 0x49, 0xEE, 0x2D, 0x4F, 0x8F, 0x3B,
+ 0x47, 0x87, 0x6D, 0x46, 0xD6, 0x3E, 0x69, 0x64,
+ 0x2A, 0xCE, 0xCB, 0x2F, 0xFC, 0x97, 0x05, 0x7A,
+ 0xAC, 0x7F, 0xD5, 0x1A, 0x4B, 0x0E, 0xA7, 0x5A,
+ 0x28, 0x14, 0x3F, 0x29, 0x88, 0x3C, 0x4C, 0x02,
+ 0xB8, 0xDA, 0xB0, 0x17, 0x55, 0x1F, 0x8A, 0x7D,
+ 0x57, 0xC7, 0x8D, 0x74, 0xB7, 0xC4, 0x9F, 0x72,
+ 0x7E, 0x15, 0x22, 0x12, 0x58, 0x07, 0x99, 0x34,
+ 0x6E, 0x50, 0xDE, 0x68, 0x65, 0xBC, 0xDB, 0xF8,
+ 0xC8, 0xA8, 0x2B, 0x40, 0xDC, 0xFE, 0x32, 0xA4,
+ 0xCA, 0x10, 0x21, 0xF0, 0xD3, 0x5D, 0x0F, 0x00,
+ 0x6F, 0x9D, 0x36, 0x42, 0x4A, 0x5E, 0xC1, 0xE0
+ },
+ new byte[] {
+ 0x75, 0xF3, 0xC6, 0xF4, 0xDB, 0x7B, 0xFB, 0xC8,
+ 0x4A, 0xD3, 0xE6, 0x6B, 0x45, 0x7D, 0xE8, 0x4B,
+ 0xD6, 0x32, 0xD8, 0xFD, 0x37, 0x71, 0xF1, 0xE1,
+ 0x30, 0x0F, 0xF8, 0x1B, 0x87, 0xFA, 0x06, 0x3F,
+ 0x5E, 0xBA, 0xAE, 0x5B, 0x8A, 0x00, 0xBC, 0x9D,
+ 0x6D, 0xC1, 0xB1, 0x0E, 0x80, 0x5D, 0xD2, 0xD5,
+ 0xA0, 0x84, 0x07, 0x14, 0xB5, 0x90, 0x2C, 0xA3,
+ 0xB2, 0x73, 0x4C, 0x54, 0x92, 0x74, 0x36, 0x51,
+ 0x38, 0xB0, 0xBD, 0x5A, 0xFC, 0x60, 0x62, 0x96,
+ 0x6C, 0x42, 0xF7, 0x10, 0x7C, 0x28, 0x27, 0x8C,
+ 0x13, 0x95, 0x9C, 0xC7, 0x24, 0x46, 0x3B, 0x70,
+ 0xCA, 0xE3, 0x85, 0xCB, 0x11, 0xD0, 0x93, 0xB8,
+ 0xA6, 0x83, 0x20, 0xFF, 0x9F, 0x77, 0xC3, 0xCC,
+ 0x03, 0x6F, 0x08, 0xBF, 0x40, 0xE7, 0x2B, 0xE2,
+ 0x79, 0x0C, 0xAA, 0x82, 0x41, 0x3A, 0xEA, 0xB9,
+ 0xE4, 0x9A, 0xA4, 0x97, 0x7E, 0xDA, 0x7A, 0x17,
+ 0x66, 0x94, 0xA1, 0x1D, 0x3D, 0xF0, 0xDE, 0xB3,
+ 0x0B, 0x72, 0xA7, 0x1C, 0xEF, 0xD1, 0x53, 0x3E,
+ 0x8F, 0x33, 0x26, 0x5F, 0xEC, 0x76, 0x2A, 0x49,
+ 0x81, 0x88, 0xEE, 0x21, 0xC4, 0x1A, 0xEB, 0xD9,
+ 0xC5, 0x39, 0x99, 0xCD, 0xAD, 0x31, 0x8B, 0x01,
+ 0x18, 0x23, 0xDD, 0x1F, 0x4E, 0x2D, 0xF9, 0x48,
+ 0x4F, 0xF2, 0x65, 0x8E, 0x78, 0x5C, 0x58, 0x19,
+ 0x8D, 0xE5, 0x98, 0x57, 0x67, 0x7F, 0x05, 0x64,
+ 0xAF, 0x63, 0xB6, 0xFE, 0xF5, 0xB7, 0x3C, 0xA5,
+ 0xCE, 0xE9, 0x68, 0x44, 0xE0, 0x4D, 0x43, 0x69,
+ 0x29, 0x2E, 0xAC, 0x15, 0x59, 0xA8, 0x0A, 0x9E,
+ 0x6E, 0x47, 0xDF, 0x34, 0x35, 0x6A, 0xCF, 0xDC,
+ 0x22, 0xC9, 0xC0, 0x9B, 0x89, 0xD4, 0xED, 0xAB,
+ 0x12, 0xA2, 0x0D, 0x52, 0xBB, 0x02, 0x2F, 0xA9,
+ 0xD7, 0x61, 0x1E, 0xB4, 0x50, 0x04, 0xF6, 0xC2,
+ 0x16, 0x25, 0x86, 0x56, 0x55, 0x09, 0xBE, 0x91
+ }
+ };
+
+ private static readonly DWord[][] MdsTable = new DWord[4][] { new DWord[256], new DWord[256], new DWord[256], new DWord[256] };
+ private static bool MdsTableBuilt;
+ private static readonly object SyncRootBuildMds = new();
+
+ private static void BuildMds() {
+ lock (SyncRootBuildMds) {
+ if (MdsTableBuilt) { return; }
+
+ var m1 = new byte[2];
+ var mX = new byte[2];
+ var mY = new byte[4];
+
+ for (var i = 0; i < 256; i++) {
+ m1[0] = P8x8[0][i]; /* compute all the matrix elements */
+ mX[0] = (byte)Mul_X(m1[0]);
+ mY[0] = (byte)Mul_Y(m1[0]);
+
+ m1[1] = P8x8[1][i];
+ mX[1] = (byte)Mul_X(m1[1]);
+ mY[1] = (byte)Mul_Y(m1[1]);
+
+ MdsTable[0][i].B0 = m1[1];
+ MdsTable[0][i].B1 = mX[1];
+ MdsTable[0][i].B2 = mY[1];
+ MdsTable[0][i].B3 = mY[1]; //SetMDS(0);
+
+ MdsTable[1][i].B0 = mY[0];
+ MdsTable[1][i].B1 = mY[0];
+ MdsTable[1][i].B2 = mX[0];
+ MdsTable[1][i].B3 = m1[0]; //SetMDS(1);
+
+ MdsTable[2][i].B0 = mX[1];
+ MdsTable[2][i].B1 = mY[1];
+ MdsTable[2][i].B2 = m1[1];
+ MdsTable[2][i].B3 = mY[1]; //SetMDS(2);
+
+ MdsTable[3][i].B0 = mX[0];
+ MdsTable[3][i].B1 = m1[0];
+ MdsTable[3][i].B2 = mY[0];
+ MdsTable[3][i].B3 = mX[0]; //SetMDS(3);
+ }
+
+ MdsTableBuilt = true;
+ }
+ }
+
+ private const uint RS_GF_FDBK = 0x14D;
+
+ private static DWord ReedSolomonMdsEncode(DWord k0, DWord k1) {
+ var r = new DWord();
+ for (var i = 0; i < 2; i++) {
+ r ^= (i > 0) ? k0 : k1; //merge in 32 more key bits
+ for (var j = 0; j < 4; j++) { //shift one byte at a time
+ var b = (byte)(r >> 24);
+ var g2 = (byte)((b << 1) ^ (((b & 0x80) > 0) ? RS_GF_FDBK : 0));
+ var g3 = (byte)(((b >> 1) & 0x7F) ^ (((b & 1) > 0) ? RS_GF_FDBK >> 1 : 0) ^ g2);
+ r.B3 = (byte)(r.B2 ^ g3);
+ r.B2 = (byte)(r.B1 ^ g2);
+ r.B1 = (byte)(r.B0 ^ g3);
+ r.B0 = b;
+ }
+ }
+ return r;
+ }
+
+
+ private static uint Mul_X(uint x) {
+ return Mx_X(x);
+ }
+ private static uint Mul_Y(uint x) {
+ return Mx_Y(x);
+ }
+
+ private static uint Mx_X(uint x) {
+ return (x ^ LFSR2(x)); //5B
+ }
+
+ private static uint Mx_Y(uint x) {
+ return (x ^ LFSR1(x) ^ LFSR2(x)); //EF
+ }
+
+
+ private const uint MDS_GF_FDBK = 0x169; //primitive polynomial for GF(256)
+
+ private static uint LFSR1(uint x) {
+ return ((x >> 1) ^ (((x & 0x01) > 0) ? MDS_GF_FDBK / 2 : 0));
+ }
+
+ static private uint LFSR2(uint x) {
+ return ((x >> 2) ^ (((x & 0x02) > 0) ? MDS_GF_FDBK / 2 : 0)
+ ^ (((x & 0x01) > 0) ? MDS_GF_FDBK / 4 : 0));
+ }
+
+ private struct DWord
+ {
+ public byte B0;
+ public byte B1;
+ public byte B2;
+ public byte B3;
+
+ private uint Value;
+
+ private DWord(uint value) : this() {
+ Value = value;
+ }
+
+ internal DWord(byte[] buffer, int offset) : this() {
+ B0 = buffer[offset + 0];
+ B1 = buffer[offset + 1];
+ B2 = buffer[offset + 2];
+ B3 = buffer[offset + 3];
+ }
+
+ public static explicit operator uint(DWord expr) {
+ return expr.Value;
+ }
+
+ public static explicit operator DWord(int value) {
+ return new DWord((uint)value);
+ }
+
+ public static explicit operator DWord(uint value) {
+ return new DWord(value);
+ }
+
+
+ public static DWord operator +(DWord expr1, DWord expr2) {
+ expr1.Value += expr2.Value;
+ return expr1;
+ }
+
+ public static DWord operator *(uint value, DWord expr) {
+ expr.Value = value * expr.Value;
+ return expr;
+ }
+
+
+ public static DWord operator |(DWord expr1, DWord expr2) {
+ expr1.Value |= expr2.Value;
+ return expr1;
+ }
+
+ public static DWord operator ^(DWord expr1, DWord expr2) {
+ expr1.Value ^= expr2.Value;
+ return expr1;
+ }
+
+ public static DWord operator <<(DWord expr, int count) {
+ expr.Value <<= count;
+ return expr;
+ }
+
+ public static DWord operator >>(DWord expr, int count) {
+ expr.Value >>= count;
+ return expr;
+ }
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public DWord RotateLeft(int n) {
+ return (DWord)((Value << n) | (Value >> (32 - n)));
+ }
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public DWord RotateRight(int n) {
+ return (DWord)((Value >> n) | (Value << (32 - n)));
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/Twofish/Twofish.cs.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/Twofish/Twofish.cs.meta
new file mode 100644
index 0000000..f2e59af
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/Twofish/Twofish.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 829fc27d22454e41833c7820d169d278
+timeCreated: 1709901703
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/Twofish/TwofishEncryptionOptions.cs b/DevsDaddy/Shared/CryptoLibrary/Modules/Twofish/TwofishEncryptionOptions.cs
new file mode 100644
index 0000000..2eba8e0
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/Twofish/TwofishEncryptionOptions.cs
@@ -0,0 +1,18 @@
+using System.Security.Cryptography;
+using System.Text;
+using DevsDaddy.Shared.CryptoLibrary.Core;
+
+namespace DevsDaddy.Shared.CryptoLibrary.Modules.Twofish
+{
+ [System.Serializable]
+ public class TwofishEncryptionOptions : IProviderOptions
+ {
+ public Encoding encoding = Encoding.UTF8;
+ public int keySize = 256;
+ public CipherMode mode = CipherMode.CBC;
+ public PaddingMode padding = PaddingMode.PKCS7;
+
+ public byte[] IV;
+ public byte[] cryptoKey;
+ }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/Twofish/TwofishEncryptionOptions.cs.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/Twofish/TwofishEncryptionOptions.cs.meta
new file mode 100644
index 0000000..294b785
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/Twofish/TwofishEncryptionOptions.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 9b2b25c8068142dab8bd78dec03a4d3e
+timeCreated: 1709901440
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/Twofish/TwofishProvider.cs b/DevsDaddy/Shared/CryptoLibrary/Modules/Twofish/TwofishProvider.cs
new file mode 100644
index 0000000..5662fe8
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/Twofish/TwofishProvider.cs
@@ -0,0 +1,94 @@
+using System;
+using System.IO;
+using System.Security.Cryptography;
+using DevsDaddy.Shared.CryptoLibrary.Core;
+
+namespace DevsDaddy.Shared.CryptoLibrary.Modules.Twofish
+{
+ ///
+ /// Twofish Crypto Provider
+ ///
+ public class TwofishProvider : ICryptoProvider
+ {
+ // Provider Options and Worker
+ private TwofishEncryptionOptions _options;
+ private Twofish _worker;
+
+ ///
+ /// Twofish Provider
+ ///
+ ///
+ public TwofishProvider(TwofishEncryptionOptions options) {
+ _options = options ?? new TwofishEncryptionOptions();
+ _worker = new Twofish() {
+ KeySize = _options.keySize,
+ Mode = _options.mode,
+ Padding = _options.padding
+ };
+
+ if (_options.IV == null)
+ _worker.GenerateIV();
+ else
+ _worker.IV = _options.IV;
+
+ if (_options.cryptoKey == null)
+ _worker.GenerateKey();
+ else
+ _worker.Key = _options.cryptoKey;
+ }
+
+ ///
+ /// Decrypt text encrypted by Twofish Provider
+ ///
+ ///
+ ///
+ public string DecryptString(string encryptedString) {
+ byte[] decrypted = DecryptBinary(Convert.FromBase64String(encryptedString));
+ return _options.encoding.GetString(decrypted);
+ }
+
+ ///
+ /// Decrypt binary data using Twofish Provider to byte array
+ ///
+ ///
+ ///
+ public byte[] DecryptBinary(byte[] encryptedBinary) {
+ var inputData = new MemoryStream(encryptedBinary);
+ var outputData = new MemoryStream();
+ using var decryptor = _worker.CreateDecryptor();
+ using (var csRead = new CryptoStream(inputData, decryptor, CryptoStreamMode.Read)) {
+ csRead.CopyTo(outputData);
+ }
+
+ var bytes = outputData.ToArray();
+ return bytes;
+ }
+
+ ///
+ /// Encrypt Plain-Text using Twofish Provider
+ ///
+ ///
+ ///
+ public string EncryptString(string decryptedString) {
+ byte[] encrypted = EncryptBinary(_options.encoding.GetBytes(decryptedString));
+ return Convert.ToBase64String(encrypted);
+ }
+
+ ///
+ /// Encrypt byte array using Twofish Provider
+ ///
+ ///
+ ///
+ public byte[] EncryptBinary(byte[] decryptedBinary) {
+ var dataStream = new MemoryStream(decryptedBinary);
+ using var encryptor = _worker.CreateEncryptor();
+ var outDataStream = new MemoryStream();
+ using (var csWrite = new CryptoStream(outDataStream, encryptor, CryptoStreamMode.Write)) {
+ dataStream.CopyTo(csWrite);
+ }
+
+ var bytes = outDataStream.ToArray();
+ return bytes;
+ }
+ }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/Twofish/TwofishProvider.cs.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/Twofish/TwofishProvider.cs.meta
new file mode 100644
index 0000000..d3b4efa
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/Twofish/TwofishProvider.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: ec782e50b2934c9db2613df7db503844
+timeCreated: 1709901431
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/XOR.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/XOR.meta
new file mode 100644
index 0000000..81fe266
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/XOR.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 1c083b5bf28e4653bde6d14e07c7463a
+timeCreated: 1709889653
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/XOR/XOREncryptionOptions.cs b/DevsDaddy/Shared/CryptoLibrary/Modules/XOR/XOREncryptionOptions.cs
new file mode 100644
index 0000000..2f68e91
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/XOR/XOREncryptionOptions.cs
@@ -0,0 +1,12 @@
+using System.Text;
+using DevsDaddy.Shared.CryptoLibrary.Core;
+
+namespace DevsDaddy.Shared.CryptoLibrary.Modules.XOR
+{
+ [System.Serializable]
+ public class XOREncryptionOptions : IProviderOptions
+ {
+ public string cryptoKey = "123456";
+ public Encoding encoding = Encoding.UTF8;
+ }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/XOR/XOREncryptionOptions.cs.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/XOR/XOREncryptionOptions.cs.meta
new file mode 100644
index 0000000..ff767bf
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/XOR/XOREncryptionOptions.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: d3cbc6cea79441a9a6b055fdceeff21d
+timeCreated: 1709895502
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/XOR/XORProvider.cs b/DevsDaddy/Shared/CryptoLibrary/Modules/XOR/XORProvider.cs
new file mode 100644
index 0000000..7b35ef6
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/XOR/XORProvider.cs
@@ -0,0 +1,86 @@
+using System;
+using System.Text;
+using DevsDaddy.Shared.CryptoLibrary.Core;
+
+namespace DevsDaddy.Shared.CryptoLibrary.Modules.XOR
+{
+ ///
+ /// XOR Crypto Provider
+ /// Works only with strings
+ ///
+ public class XORProvider : ICryptoProvider
+ {
+ // Provider Options
+ private XOREncryptionOptions _options;
+
+ ///
+ /// XOR-Provicer
+ ///
+ ///
+ public XORProvider(XOREncryptionOptions options = null) {
+ _options = options ?? new XOREncryptionOptions();
+ }
+
+ ///
+ /// Decrypt String (Warning! For XOR Encrypt/Decrypt methods are similar, because it is XOR)
+ ///
+ ///
+ ///
+ public string DecryptString(string encryptedString) {
+ return EncryptOrDecrypt(encryptedString, _options.cryptoKey);
+ }
+
+ ///
+ /// Decrypt Binary (Not Supported for XOR)
+ ///
+ ///
+ ///
+ ///
+ public byte[] DecryptBinary(byte[] encryptedBinary) {
+ throw new Exception($"Failed to decrypt byte array, because {this.GetType()} support only plain text.");
+ }
+
+ ///
+ /// Encrypt String (Warning! For XOR Encrypt/Decrypt methods are similar, because it is XOR)
+ ///
+ ///
+ ///
+ public string EncryptString(string decryptedString) {
+ return EncryptOrDecrypt(decryptedString, _options.cryptoKey);
+ }
+
+ ///
+ /// Encrypt Binary (Not Supported for XOR)
+ ///
+ ///
+ ///
+ ///
+ public byte[] EncryptBinary(byte[] decryptedBinary) {
+ throw new Exception($"Failed to decrypt byte array, because {this.GetType()} support only plain text.");
+ }
+
+
+ ///
+ /// Encrypt / Decrypt via XOR-mechanism
+ ///
+ ///
+ ///
+ ///
+ private string EncryptOrDecrypt(string text, string key)
+ {
+ var result = new StringBuilder();
+ for (int c = 0; c < text.Length; c++)
+ {
+ char character = text[c];
+ uint charCode = (uint)character;
+ int keyPosition = c % key.Length;
+ char keyChar = key[keyPosition];
+ uint keyCode = (uint)keyChar;
+ uint combinedCode = charCode ^ keyCode;
+ char combinedChar = (char)combinedCode;
+ result.Append(combinedChar);
+ }
+ return result.ToString();
+ }
+ }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/XOR/XORProvider.cs.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/XOR/XORProvider.cs.meta
new file mode 100644
index 0000000..33a7f59
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/XOR/XORProvider.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 0fb964da15ef495dbb5b96bd88f8c84d
+timeCreated: 1709895421
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/xxHash.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/xxHash.meta
new file mode 100644
index 0000000..0672d94
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/xxHash.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 618e4675bfe348f8ba8a86b4f9ba16fc
+timeCreated: 1709889657
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/xxHash/xxHashEncryptionOptions.cs b/DevsDaddy/Shared/CryptoLibrary/Modules/xxHash/xxHashEncryptionOptions.cs
new file mode 100644
index 0000000..e7e95cf
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/xxHash/xxHashEncryptionOptions.cs
@@ -0,0 +1,20 @@
+using System.Text;
+using DevsDaddy.Shared.CryptoLibrary.Core;
+
+namespace DevsDaddy.Shared.CryptoLibrary.Modules.xxHash
+{
+ [System.Serializable]
+ public class xxHashEncryptionOptions : IProviderOptions
+ {
+ public uint PRIME32_1 = 2654435761U;
+ public uint PRIME32_2 = 2246822519U;
+ public uint PRIME32_3 = 3266489917U;
+ public uint PRIME32_4 = 668265263U;
+ public uint PRIME32_5 = 374761393U;
+
+ public int length = 16;
+ public uint seed = 0;
+
+ public Encoding encoding = Encoding.UTF8;
+ }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/xxHash/xxHashEncryptionOptions.cs.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/xxHash/xxHashEncryptionOptions.cs.meta
new file mode 100644
index 0000000..405cba3
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/xxHash/xxHashEncryptionOptions.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 70b4efc0212345a2b0c82cd1fbfcc225
+timeCreated: 1709895026
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/xxHash/xxHashProvider.cs b/DevsDaddy/Shared/CryptoLibrary/Modules/xxHash/xxHashProvider.cs
new file mode 100644
index 0000000..b2236fd
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/xxHash/xxHashProvider.cs
@@ -0,0 +1,124 @@
+using System;
+using DevsDaddy.Shared.CryptoLibrary.Core;
+
+namespace DevsDaddy.Shared.CryptoLibrary.Modules.xxHash
+{
+ ///
+ /// xxHash Provider
+ /// Can Hash for plain text or byte array
+ ///
+ public class xxHashProvider : ICryptoProvider
+ {
+ // Provider Options
+ private xxHashEncryptionOptions _options;
+
+ ///
+ /// xxHash Provider
+ ///
+ ///
+ public xxHashProvider(xxHashEncryptionOptions options = null) {
+ _options = options ?? new xxHashEncryptionOptions();
+ }
+
+ ///
+ /// Decrypt String (Not Supported for hashing)
+ ///
+ ///
+ ///
+ ///
+ public string DecryptString(string encryptedString) {
+ throw new Exception($"Failed to decrypt text, because {this.GetType()} doesn't support decryption.");
+ }
+
+ ///
+ /// Decrypt Binary (Not Supported for hashing)
+ ///
+ ///
+ ///
+ ///
+ public byte[] DecryptBinary(byte[] encryptedBinary) {
+ throw new Exception($"Failed to decrypt text, because {this.GetType()} doesn't support decryption.");
+ }
+
+ ///
+ /// Get xxHash for plain-text
+ ///
+ ///
+ ///
+ public string EncryptString(string decryptedString) {
+ return Convert.ToString(EncryptBinary(_options.encoding.GetBytes(decryptedString)));
+ }
+
+ ///
+ /// Get xxHash for byte array
+ ///
+ ///
+ ///
+ public byte[] EncryptBinary(byte[] decryptedBinary) {
+ uint h32;
+ int index = 0;
+
+ if (_options.length >= 16)
+ {
+ int limit = _options.length - 16;
+ uint v1 = _options.seed + _options.PRIME32_1 + _options.PRIME32_2;
+ uint v2 = _options.seed + _options.PRIME32_2;
+ uint v3 = _options.seed;
+ uint v4 = _options.seed - _options.PRIME32_1;
+
+ do
+ {
+ uint read_value = (uint)(decryptedBinary[index++] | decryptedBinary[index++] << 8 | decryptedBinary[index++] << 16 | decryptedBinary[index++] << 24);
+ v1 += read_value * _options.PRIME32_2;
+ v1 = (v1 << 13) | (v1 >> 19);
+ v1 *= _options.PRIME32_1;
+
+ read_value = (uint)(decryptedBinary[index++] | decryptedBinary[index++] << 8 | decryptedBinary[index++] << 16 | decryptedBinary[index++] << 24);
+ v2 += read_value * _options.PRIME32_2;
+ v2 = (v2 << 13) | (v2 >> 19);
+ v2 *= _options.PRIME32_1;
+
+ read_value = (uint)(decryptedBinary[index++] | decryptedBinary[index++] << 8 | decryptedBinary[index++] << 16 | decryptedBinary[index++] << 24);
+ v3 += read_value * _options.PRIME32_2;
+ v3 = (v3 << 13) | (v3 >> 19);
+ v3 *= _options.PRIME32_1;
+
+ read_value = (uint)(decryptedBinary[index++] | decryptedBinary[index++] << 8 | decryptedBinary[index++] << 16 | decryptedBinary[index++] << 24);
+ v4 += read_value * _options.PRIME32_2;
+ v4 = (v4 << 13) | (v4 >> 19);
+ v4 *= _options.PRIME32_1;
+
+ } while (index <= limit);
+
+ h32 = ((v1 << 1) | (v1 >> 31)) + ((v2 << 7) | (v2 >> 25)) + ((v3 << 12) | (v3 >> 20)) + ((v4 << 18) | (v4 >> 14));
+ }
+ else
+ {
+ h32 = _options.seed + _options.PRIME32_5;
+ }
+
+ h32 += (uint)_options.length;
+
+ while (index <= _options.length - 4)
+ {
+ h32 += (uint)(decryptedBinary[index++] | decryptedBinary[index++] << 8 | decryptedBinary[index++] << 16 | decryptedBinary[index++] << 24) * _options.PRIME32_3;
+ h32 = ((h32 << 17) | (h32 >> 15)) * _options.PRIME32_4;
+ }
+
+ while (index < _options.length)
+ {
+ h32 += decryptedBinary[index] * _options.PRIME32_5;
+ h32 = ((h32 << 11) | (h32 >> 21)) * _options.PRIME32_1;
+ index++;
+ }
+
+ h32 ^= h32 >> 15;
+ h32 *= _options.PRIME32_2;
+ h32 ^= h32 >> 13;
+ h32 *= _options.PRIME32_3;
+ h32 ^= h32 >> 16;
+
+ return BitConverter.GetBytes(h32);
+ }
+ }
+}
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Modules/xxHash/xxHashProvider.cs.meta b/DevsDaddy/Shared/CryptoLibrary/Modules/xxHash/xxHashProvider.cs.meta
new file mode 100644
index 0000000..86d88a2
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Modules/xxHash/xxHashProvider.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 6a8f06d0ba9342b4a7586df87c38df6b
+timeCreated: 1709895032
\ No newline at end of file
diff --git a/DevsDaddy/Shared/CryptoLibrary/Preview.png b/DevsDaddy/Shared/CryptoLibrary/Preview.png
new file mode 100644
index 0000000..d0ba0d4
Binary files /dev/null and b/DevsDaddy/Shared/CryptoLibrary/Preview.png differ
diff --git a/DevsDaddy/Shared/CryptoLibrary/Preview.png.meta b/DevsDaddy/Shared/CryptoLibrary/Preview.png.meta
new file mode 100644
index 0000000..602674e
--- /dev/null
+++ b/DevsDaddy/Shared/CryptoLibrary/Preview.png.meta
@@ -0,0 +1,114 @@
+fileFormatVersion: 2
+guid: ccbed3d5bb66003438818e7ea5bc4537
+TextureImporter:
+ internalIDToNameTable: []
+ externalObjects: {}
+ serializedVersion: 12
+ mipmaps:
+ mipMapMode: 0
+ enableMipMap: 0
+ sRGBTexture: 1
+ linearTexture: 0
+ fadeOut: 0
+ borderMipMap: 0
+ mipMapsPreserveCoverage: 0
+ alphaTestReferenceValue: 0.5
+ mipMapFadeDistanceStart: 1
+ mipMapFadeDistanceEnd: 3
+ bumpmap:
+ convertToNormalMap: 0
+ externalNormalMap: 0
+ heightScale: 0.25
+ normalMapFilter: 0
+ flipGreenChannel: 0
+ isReadable: 0
+ streamingMipmaps: 0
+ streamingMipmapsPriority: 0
+ vTOnly: 0
+ ignoreMipmapLimit: 0
+ grayScaleToAlpha: 0
+ generateCubemap: 6
+ cubemapConvolution: 0
+ seamlessCubemap: 0
+ textureFormat: 1
+ maxTextureSize: 2048
+ textureSettings:
+ serializedVersion: 2
+ filterMode: 1
+ aniso: 1
+ mipBias: 0
+ wrapU: 1
+ wrapV: 1
+ wrapW: 0
+ nPOTScale: 0
+ lightmap: 0
+ compressionQuality: 50
+ spriteMode: 1
+ spriteExtrude: 1
+ spriteMeshType: 1
+ alignment: 0
+ spritePivot: {x: 0.5, y: 0.5}
+ spritePixelsToUnits: 100
+ spriteBorder: {x: 0, y: 0, z: 0, w: 0}
+ spriteGenerateFallbackPhysicsShape: 1
+ alphaUsage: 1
+ alphaIsTransparency: 1
+ spriteTessellationDetail: -1
+ textureType: 8
+ textureShape: 1
+ singleChannelComponent: 0
+ flipbookRows: 1
+ flipbookColumns: 1
+ maxTextureSizeSet: 0
+ compressionQualitySet: 0
+ textureFormatSet: 0
+ ignorePngGamma: 0
+ applyGammaDecoding: 0
+ swizzle: 50462976
+ cookieLightType: 0
+ platformSettings:
+ - serializedVersion: 3
+ buildTarget: DefaultTexturePlatform
+ maxTextureSize: 2048
+ resizeAlgorithm: 0
+ textureFormat: -1
+ textureCompression: 1
+ compressionQuality: 50
+ crunchedCompression: 0
+ allowsAlphaSplitting: 0
+ overridden: 0
+ ignorePlatformSupport: 0
+ androidETC2FallbackOverride: 0
+ forceMaximumCompressionQuality_BC6H_BC7: 0
+ - serializedVersion: 3
+ buildTarget: Standalone
+ maxTextureSize: 2048
+ resizeAlgorithm: 0
+ textureFormat: -1
+ textureCompression: 1
+ compressionQuality: 50
+ crunchedCompression: 0
+ allowsAlphaSplitting: 0
+ overridden: 0
+ ignorePlatformSupport: 0
+ androidETC2FallbackOverride: 0
+ forceMaximumCompressionQuality_BC6H_BC7: 0
+ spriteSheet:
+ serializedVersion: 2
+ sprites: []
+ outline: []
+ physicsShape: []
+ bones: []
+ spriteID: 5e97eb03825dee720800000000000000
+ internalID: 0
+ vertices: []
+ indices:
+ edges: []
+ weights: []
+ secondaryTextures: []
+ nameFileIdTable: {}
+ mipmapLimitGroupName:
+ pSDRemoveMatte: 0
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/README.md b/README.md
index 51374eb..48e619b 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,110 @@
-# UnityCrypto
-Powerful Cryptography and Security Library for your application. Dozens of variations of cryptographic functions and hashing in a single library.
+# Unity Advanced Audio Framework
+
+**Unity Crypto Library** is a set of free and open source **cross-platform tools** for using **cryptographic and hash functions** in your games.
+It also contains helper classes for handling files and web requests for your convenience.
+
+I periodically update possible algorithms based on the latest research in crypto-graphy.
+
+## Get Started
+**Unity Crypto Library** is designed for your application and games security and using only default API's like **System** and **UnityEngine**.
+
+**Installation process:**
+- Download and import latest release from this page;
+- See usage examples below;
+
+## Usage
+**You can use a simple controller for fast encryption/decryption:**
+```csharp
+// Setup Default Crypto-Provider
+CryptoController.SetDefaultProvider(new AESProvider(new AESEncryptionOptions {
+ cryptoKey = "myCryptoKey"
+}));
+
+// Simple Plain-Text Encryption-Decryption
+string encryptedText = CryptoController.Encrypt("MyTextToEncrypt");
+string decryptedText = CryptoController.Decrypt(encryptedText);
+
+// Or with in-line crypto-provider
+string encryptedText2 = CryptoController.Encrypt("TextToEncrypt", new AESProvider(new AESEncryptionOptions {
+ cryptoKey = "myCryptoKey"
+}));
+```
+
+**Or initial crypto providers manually:***
+```csharp
+// Create your provider
+AESProvider provider = new AESProvider(new AESEncryptionOptions {
+ cryptoKey = "myCryptoKey"
+});
+
+// Work with provider
+string encryptedText = provider.EncryptString("MyTextToEncrypt");
+string decryptedText = provider.DecryptString(encryptedText);
+```
+
+**Also you can read/write files using util class (similar like CryptoController just for files):***
+```csharp
+// Setup Default Crypto-provider for Files
+CryptoFile.SetDefaultProvider(new AESProvider(new AESEncryptionOptions {
+ cryptoKey = "key"
+}));
+
+// Read and Decrypt File
+string decryptedText = CryptoFile.ReadText("path_to_encrypted_file");
+
+// Encrypt plain-text and save to file
+bool writtenFile = CryptoFile.WriteText("path_to_encrypted_file", decryptedText);
+```
+
+## Crypto-Algorithms
+**Library contains popular crypto modules:**
+- **AES** (Recommended);
+- **Triple DES** (Recommended);
+- **BlowFish** (Recommended);
+- **Twofish** (Recommended);
+- **RSA** (Recommended for Web);
+- **DES**;
+- **Base64**;
+- **XOR** (Only strings support, no byte array);
+
+**Code Sample:**
+```csharp
+string encrypted = CryptoController.Encrypt("TextToEncrypt", new AESProvider(new AESEncryptionOptions {
+ cryptoKey = "myCryptoKey"
+}));
+
+// Return Encrypted
+Debug.Log(encrypted);
+```
+
+## Hashing
+**Library contains popular hashing functions:**
+- **SHA1** / **SHA256** / **SHA512** (Recommended);
+- **PBKDF2** (Recommended);
+- **MD5**;
+- **xxHash**;
+- **RIPEMD-160**;
+- **CRC32**;
+
+**Code Sample:**
+```csharp
+string hashed = CryptoController.Encrypt("TextToEncrypt", new MD5Provider(new MD5EncryptionOptions { }));
+
+// Return Hashed
+Debug.Log(hashed);
+```
+
+## Examples
+See framework usage examples in other projects:
+* Game Shield - Unity Game Security and Anti-Cheat Toolkit;
+
+## Coming Soon (TO-DO)
+**I plan to add the following functionality in the near future:**
+- Sending and accepting encrypted HTTP requests and working with encrypted data on sockets with server examples on NodeJS / CSharp;
+- Read / Write files using chunks for large amounts of data;
+- New Hashing Modules: Argon2, BCrypt, SCrypt, Whirlpool;
+- New Encryption Modules like SPHINCS+;
+
+## Support Me
+Like my libraries or assets?
+Buy me a coffee.
\ No newline at end of file