Wednesday, 29 May 2019

C# Encrypt and Decrypt String

public string Encrypt(string plainText) { try { var sb = new System.Text.StringBuilder(); var bytes = System.Text.Encoding.Unicode.GetBytes(plainText); foreach (var t in bytes) sb.Append(t.ToString("X2")); return sb.ToString(); } catch { return null; } } public string Decrypt(string encryptedText) { try { var bytes = new byte[encryptedText.Length / 2]; for (var i = 0; i < bytes.Length; i++) bytes[i] = System.Convert.ToByte(encryptedText.Substring(i * 2, 2), 16); return System.Text.Encoding.Unicode.GetString(bytes); } catch { return null; } }

No comments:

SQL: Generate a range of numbers

SELECT ones.n + 10*tens.n + 100*hundreds.n + 1000*thousands.n FROM       (VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) ones(n),      (VALU...