Timestamp, random number generation, Random Number Generation
Static void Main (string [] args)
{
String s = getTimestamp ();
String ss = getNoncestr ();
Console. WriteLine (ss );
Console. WriteLine (s );
Console. ReadKey ();
}
========================================================== ========================================================== ==========
/// <Summary> /// generate the timestamp /// the number of seconds since 00:00:00, January 1, January 1, 1970, that is, the current time, finally, it needs to be converted to the string format // </summary> /// <returns> </returns> public string getTimestamp () {TimeSpan ts = DateTime. utcNow-new DateTime (1970, 1, 1, 0, 0, 0); return Convert. toInt64 (ts. totalSeconds ). toString ();}
========================================================== ==========
Public static string getNoncestr ()
{
Random random = new Random ();
Return MD5Util. GetMD5 (random. Next (1000). ToString (), "GBK ");
}
Public class MD5Util
{
Public MD5Util ()
{
//
// TODO: add the constructor logic here
//
}
/** Obtain the uppercase MD5 Signature result */
Public static string GetMD5 (string enpolicstr, string charset)
{
String retStr;
MD5CryptoServiceProvider m5 = new MD5CryptoServiceProvider ();
// Create an md5 object
Byte [] inputBye;
Byte [] outputBye;
// Use GB2312 encoding to convert a string into a byte array.
Try
{
InputBye = Encoding. GetEncoding (charset). GetBytes (enpolicstr );
}
Catch (Exception ex)
{
InputBye = Encoding. GetEncoding ("GB2312"). GetBytes (enpolicstr );
}
OutputBye = m5.ComputeHash (inputBye );
RetStr = System. BitConverter. ToString (outputBye );
RetStr = retStr. Replace ("-", ""). ToUpper ();
Return retStr;
}
}