public byte[] ConvertHexToBinary(string hex_text) { try { return(InternalMethods.HexStringToBytes(hex_text)); } catch (Exception exc) { LogInternalEvent(exc, 4); throw exc; } }
public string DecryptString(string value, string keyString) { try { byte[] resultBA = new byte[value.Length / 2], valueBA = new byte[value.Length / 2]; byte[] iv = new byte[] { 0x14, 0xD7, 0x5B, 0xA2, 0x47, 0x83, 0x0F, 0xC4 }; System.Text.ASCIIEncoding ascEncoding = new System.Text.ASCIIEncoding(); byte[] key = new byte[24]; ascEncoding.GetBytes(keyString, 0, keyString.Length < 24?keyString.Length:24, key, 0); MemoryStream memStream = new MemoryStream(); byte[] tempBA = InternalMethods.HexStringToBytes(value); memStream.Write(tempBA, 0, tempBA.Length); memStream.Position = 0; System.Security.Cryptography.TripleDES cryptoServiceProvider = System.Security.Cryptography.TripleDESCryptoServiceProvider.Create(); System.Security.Cryptography.ICryptoTransform decryptor = cryptoServiceProvider.CreateDecryptor(key, iv); System.Security.Cryptography.CryptoStream cStream = new System.Security.Cryptography.CryptoStream( memStream, decryptor, System.Security.Cryptography.CryptoStreamMode.Read); cStream.Read(resultBA, 0, resultBA.Length); cStream.Close(); return(ascEncoding.GetString(resultBA)); } catch (Exception exc) { LogEvent("Decryption failure. Returning original value" + Environment.NewLine + exc.Source, "DecryptString()", exc.ToString(), 3); return(value); } }