/// <summary> /// </summary> /// <param name="key"> /// </param> /// <param name="hexString"> /// </param> /// <param name="encoding"> /// </param> /// <returns> /// </returns> private string DecryptHexString(string key, string hexString, Encoding encoding) { BlowFish bfe = null; byte[] b = (encoding == Encoding.ASCII) ? Encoding.Default.GetBytes(key) : encoding.GetBytes(key); bfe = new BlowFish(b, 0, b.Length); int discarded = 0; byte[] enc = HexEncoding.HexStringToByteArray(hexString, out discarded); var dec = new byte[enc.Length]; bfe.Decrypt(enc, 0, dec, 0, enc.Length); string str = (encoding == Encoding.ASCII) ? Encoding.Default.GetString(dec) : encoding.GetString(dec); return(AsciiToHex(str, encoding)); }
/// <summary> /// </summary> /// <param name="hexString"> /// </param> /// <param name="encoding"> /// </param> /// <returns> /// </returns> private string HexToAscii(string hexString, Encoding encoding) { return(HexEncoding.HexToASCII(hexString, encoding)); }
/// <summary> /// </summary> /// <param name="asciiString"> /// </param> /// <param name="encoding"> /// </param> /// <returns> /// </returns> private string AsciiToHex(string asciiString, Encoding encoding) { return(HexEncoding.ASCIIToHex(asciiString, encoding)); }