Archive for the ‘Visual C#’ Category

Convert Westen datetime to Japanese calendar

August 11, 2009 Leave a comment
using System;
using System.Globalization;

class WarekiSample1 {
   static void Main() {
      DateTime 日付 = new DateTime(2003, 7, 1, 12, 34, 56);
      JapaneseCalendar カレンダー = new JapaneseCalendar();
      // 出力:4
      string [] 元号名 = { "明治", "大正", "昭和", "平成" };
      Console.WriteLine(元号名[カレンダー.GetEra(日付) - 1]);
      // 出力:平成
      // 出力:15
Categories: Visual C# Tags:

Generate a MD5 string

December 15, 2006 Leave a comment

In any systems, you must design an user authentication to check if an user has a right permission to log in, at that time user’s information as password must be enscripted. With .NET, you can use one of two algorithms, SHA1 or MD5, to generate an enscripted result. These algorithms allow you to get a 32bits, 64bits or 128bit string with inputted characters and there is no way to descript because these algorithms are only one-way

Here is a short script that can help you to create a enscripted string using C#

String resultPassword;
Byte[] data;
MD5 hashMd5 = new MD5CryptoServiceProvider();
data = hashMD5.ComputeHash(Encoding.ASCII.GetBytes(inputPassword.ToCharArray()));
for (int i = 0; i < data.Length-1; i++)
resultPassword += data[i].ToString("X2");

After finishing FOR loop….you can get your enscripted string with “resultPassword”. Please remember to import System.Security.Cryptography library before executing

Categories: Visual C# Tags: