Timestamp, random number generation, Random Number Generation

Source: Internet
Author: User

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;
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.