public static string Encrypt(string dataToEncrypt) { if (string.IsNullOrWhiteSpace(dataToEncrypt)) { return(dataToEncrypt); } byte[] inputBytes = RandomStringGenerator.GetBytesFromString(dataToEncrypt); var des3Encrypt = CreateEncryptor(); MemoryStream mstream = new MemoryStream(); CryptoStream cstream = new CryptoStream(mstream, des3Encrypt, CryptoStreamMode.Write); cstream.Write(inputBytes, 0, inputBytes.Length); cstream.FlushFinalBlock(); byte[] encryptedDataBytes = mstream.ToArray(); mstream.Close(); cstream.Close(); return(RandomStringGenerator.ToEncodedString(encryptedDataBytes)); }
private static void InitializeObscurity() { encryptKeyArray = new string[_randomizationLevel]; for (int i = 0; i < encryptKeyArray.Length; i++) { bool validated = false; while (!validated) { encryptKeyArray[i] = RandomStringGenerator.GenerateRandomString(24, 24, 2, 2, 2, 2); validated = RandomStringGenerator.ValidateRandomString(encryptKeyArray[i], 24, 24, 2, 2, 2, 2); } } initVectorArray = new string[_randomizationLevel]; for (int i = 0; i < initVectorArray.Length; i++) { bool validated = false; while (!validated) { initVectorArray[i] = RandomStringGenerator.GenerateRandomString(16, 16, 2, 2, 2, 2); validated = RandomStringGenerator.ValidateRandomString(initVectorArray[i], 16, 16, 2, 2, 2, 2); } } }