Thứ Tư, 26 tháng 3, 2014

Mã hóa HMACSHA256

    private string HMACSHA256(string message, string secret)
    {
        secret = secret ?? "";
        var encoding = new System.Text.ASCIIEncoding();
        byte[] keyByte = encoding.GetBytes(secret);
        byte[] messageBytes = encoding.GetBytes(message);
        using (var hmacsha256 = new HMACSHA256(keyByte))
        {
            byte[] hashmessage = hmacsha256.ComputeHash(messageBytes);
            string sbinary = "";
            for (int i = 0; i < hashmessage.Length; i++)
            {
                sbinary += hashmessage[i].ToString("x2"); // hex format
            }
            return sbinary;
        }
    }

Thứ Sáu, 7 tháng 3, 2014

Gửi 1 file word qua máy in để in sử dụng c#

string[] files = Directory.GetFiles(Environment.CurrentDirectory, "*.docx");
foreach (var file in files)
{
 System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo(file);
 info.Arguments = "\"" + printDialog1.PrinterSettings.PrinterName + "\"";
 info.CreateNoWindow = true;
 info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
 info.UseShellExecute = true;
 info.Verb = "PrintTo";
 System.Diagnostics.Process.Start(info);
}