National Business Password (v) generation and verification of software authorization code based on SM2

Source: Internet
Author: User

The advantage of using public key algorithm as a software registration algorithm is that cracker is difficult to get keygen by tracking verification algorithm. Below, the method for software registration using the SM2 algorithm is described.

Generate Authorization Code

    1. Generating SM2 instances
    2. Generate random numbers using random number generators r∈[1,n-1]
    3. Calculate Elliptic Curve point r=[r]g= (Xr,yr)
    4. Computes the hash value h=sm3 (user name ∥xr∥yr)
    5. Calculates the serial number S≡ (r-h * d) mod n, where D is the private key and N is the order of the G-point
    6. Use S and h together as the user's authorization code
Verify Authorization Code
    1. Generating SM2 instances
    2. Extract serial number S and hash value H
    3. Compute Point R≡ ([S]g + [h]q) mod p, where Q is the public key and P is the number of element elements
    4. Compute hash Value h ' =sm3 (user name ∥xr∥yr)
    5. If H ' =h is registered successfully; if H ' ≠h, then registration fails

The method of generation and verification of authorization codes has been integrated in the SM2 class of the open dynamic Library OpenSM.dll of the National Commercial cryptography algorithm. The corresponding member functions are:

<summary>///Generate Authorization Code///</summary>///<param name= "userId" > User registration information </param>///<param name = "Privatekey" > Private key </param>///<returns> Authorization Code </returns>//<remarks> Note: For the same registration information, Each generated authorization code is not the same </remarks>public Eclicensekey Licensekeymaker (byte[] userId, BigInteger privatekey);///< summary>///Generate Authorization Code//</summary>///<param name= "userId" > User registration Information </param>///<param name= " Privatekey "> Private key </param>///<param name=" R "> random number, whose value is at [1, N-1],n is the order of the G-point </param>///<returns> Authorization Code </returns>///<remarks> Note: For the same registration information and the same r, each generated authorization code is consistent </remarks>public Eclicensekey Licensekeymaker (byte[] userId, BigInteger Privatekey, BigInteger R);///<summary>///Check Authorization code///</summary>// /<param name= "userId" > User registration Information </param>///<param name= "Registercode" > Registration Code </param>///< param name= "PublicKey" > Public key </param>///<returns>///true: Validation passed//Fasle: Checksum failed//</returns>public bool Licensekeyverifier (byte[] userId, Eclicensekey registercode, Ecpoint publickey); 

The Eclicensekey class is defined as follows:

<summary>///SM2 cipher algorithm keygen generate Authorization code format///</summary>public class eclicensekey{public readonly BigInteger Mkey; Public ReadOnly BigInteger mhash;///<summary>///constructor///</summary>///<param name= "key" > Authorization Code </ param>///<param name= "Hash" > Hash value </param>public eclicensekey (BigInteger key, BigInteger hash) { This.mkey = Key;this.mhash = hash;}}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

National Business Password (v) generation and verification of software authorization code based on SM2

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.