Postsharp 4.0 registration machine implementation process

Source: Internet
Author: User
Tags key string reflector

Postsharp is A. Net-based AOP framework that emphasizes easy to learn and use.

What is AOP? Http://wayfarer.cnblogs.com/articles/241024.html

Preparations
  1. Install. Net reflector or similar tools
  2. Install the reflector. bamlviewer plug-in on. NET reflector to view the XAML. : Http://reflectoraddins.codeplex.com/releases
  3. Go to postsharp official website to download the latest version (4.0.29), and install: http://www.postsharp.net/download
Start working

Find the installation directory. I use Win8 and vs2012. The installation directory is c: \ Users \ [user name] \ appdata \ Local \ Microsoft \ visualstudio \ 10.0 \ extensions \*

Vs2012 c: \ Users \ [user name] \ appdata \ Local \ Microsoft \ visualstudio \ 12.0 \ extensions \*

The final * is random. Click it one by one or search for the file postsharp. dll. You will know the result.

First, let's take a look at the registration interface, and then use. Net reflectorto decompile postsharp.hq.v3.0.exe to find the corresponding interface. The registration interface is as follows. It is a WPF window.

After some searching, we found it was enterlicensekeypage.

Go to this interface and configure postsharp. HQ. Licensing. enterlicensekeypage.

  public override void OnNext()    {        this.__PS___z_aspect29.OnMethodEntry(null);        try        {            string str;            License license = License.Deserialize(this.licenseKeyTextBox.Text);.....
View code

Are you sure you want to register the verification code in the postsharp. SDK. extensibility. Licensing. License class (this class is in the DLL postsharp. settings. dll)

It can be seen from several methods in the class that this class includes the function of generating a registration code and verifying registration. Use DSA Encryption

public class License{    public static License Create(LicensedProduct product);    public static License Deserialize(string licenseString);    public string Serialize();    public void Sign(byte signatureKeyId, string privateKey);    public virtual bool Validate(byte[] publicKeyToken, out string errorDescription);    public bool VerifySignature();    public bool VerifySignature(DSA publicKey);   ...}
View code

You can use the following code to generate a registration code

License LIC = license. create (licensedproduct. postsharp30); LIC. licenseguid = guid. newguid (); LIC. licensetype = (byte) licensetype. commercial; LIC. product = licensedproduct. postsharp30; LIC. sign (1, privatekey); string Sn = Lic. serialize (); // The final registration code

Do you think it's all done here? Wrong. Have you obtained the private key?

Of course, you have the ability to get the private key. This step is complete. But I can't find it. I can only find another way.

 

Further research finds that the public key is provided in the postsharp. SDK. extensibility. Licensing. cryptoutilities class.

public static class CryptoUtilities{    // Fields    private static readonly DSA productionPublicKey0 = DSA.Create();    private static readonly DSA productionPublicKey1 = DSA.Create();    // Methods    static CryptoUtilities()    {        productionPublicKey0.FromXmlString("<DSAKeyValue><P>9cMyBYBokidciAghqE1POnEbcxpBui3PfazddrQjndkDtPskGvBcjS8LIStB/jR0SICKmLMwl7WoocpdXgYTOopgKJ33E4NOIhc1vbQR6vCCidGWlN88hUKCQJ8cGzme/LDmUT5zfK3TfM6LkMU1fYTNARrefIZkSlg4GGIjZ38=</P><Q>m9h5p2kl1vlwuw12AOQbem3yDXU=</Q><G>pBkhekdI1vk084zMbubnu7qtDyTid6x01crQJiERfmk2HgFt13dXHwei/1kgrRJPWrtZVRKMmO8w+p4jfle82n2/BaFNBLouUoQ/fBYPPdDZBocd/tXqBduF5zq1S12tDv8TIIarMTRtj18F5e68cxBPbweVs4n8meqLEQL5AwA=</G><Y>e2otaOKaVFxnEoHI4g1f7BCcrOaAwd1/GTMkEXGaNw3CYucIuOJdvlZEWa/pa4DTUeK4McHOXRJsZMQdHaoh+dK17NdmMxTa2UMokyoIdayu9kw9TbWUy2zXovJ8CHJVP4RU8wlJk1RKjeMuSK3lYPgo2RTbV9UbU2qK1gmVwg4=</Y><J>AAAAAZOzu4FkAIr0MjlqqHtPNWrFTfjw4/qDWuFvHEf7ioaj8vqRao8mbqsLueqvYIYQ8g8w2WNWFAOG6e8waiQhX2O/DRSZNbc/JfdjQqlPli5be6FqNsGnjKXdEt2boONKU/fpGx/m69V+a/4jxg==</J><Seed>1B0yRR/A/kmE1zMUIFiEMmJ328M=</Seed><PgenCounter>Xg==</PgenCounter></DSAKeyValue>");        productionPublicKey1.FromXmlString("<DSAKeyValue><P>vAmBC+eZJaZa7HdlTDAgsfcT0QSjqN8d8fEeZ9E1kxfIAYGerlHFHW/A5muBYy8FyO7W8r4mqxpxcvFQEeEqVe89BUXecHjh6FkTEsT25r/nbV4jnZBxNz16qb7A6t8MCr0jzuzrIGFVP5VG/ad0s/1078WqpwQqJQXHmH/lXX0=</P><Q>+RdtGnwCJw4u2H/goSLtaAGr1U0=</Q><G>sxQQgHIuRgYOMtB+r7EGRO/OTRGXhUrFyZ1R9nVerGGC2juEVWSoydr2JquILOwIO7+1kIOwbkhCjNlZIAdvWRlN5COF7gHfPi1dSX7LzDcNbZDADvrOUmk1KG3hZ3Vf67XIbug2/nq8aij7gbEs4eA26EWWpObO0a+e2QmsQII=</G><Y>dP073SH4QG5KiV5BbZEDLiV3/D2eD18D9jsMVD1p+eMZsffU88/Pxfen1Pe5cyulw8gQkEvlAa3GEmGsaGaa7Qp245NPD8fbEOLFu3tdwMhw/ylRHpjTS7BDRjvGeyGwSS0WTWQCwCyI8LN6Rvg7p4RfhHIaAWWkTJNVAG7AN7g=</Y><J>wUCV+9KzxPW+J3/DIm3sIfVf29Z8u5zPXnEZbMTrkWwdgOTSPuXimtiQku8knyWD3iC+GqyhtoFqdgXqQS6WcadAABb2U5mMTL0V1o6Jy6c0cyPb9blmf5wdZxMKVlXe9lcAO8rP16XhQGVs</J><Seed>h7zytTPqA9Ue3F7c/j+9iXW4Ebw=</Seed><PgenCounter>Aag=</PgenCounter></DSAKeyValue>");    } }
View code

To verify Registration, use the above Public Key for verification.

So can you generate your own public key and private key to replace the public key of the postsharp. SDK. extensibility. Licensing. cryptoutilities class? The answer is yes.

First, let's see how to generate the public key and private key.

Dsacryptoserviceprovider dsac = new dsacryptoserviceprovider (); string strpublic = dsac. toxmlstring (false); // public key string strprivate = dsac. toxmlstring (true); // Private Key

The result is as follows:

Public Key

<DSAKeyValue><P>gSFAXq2fbk0P+6y1G6aYXlUPdESfs42kaF/v4pfkt9sNx1bx8Ni4IVzXdgtDLKhIpL9cv6Ho0pEM5qCVZ0oY8QZJpt8PC4ZEiCEgWFGLLLooriZmJPwsEQtcjB/sz4lvvO9oFrLnrYS16e3FCriImDTBVtv3TVptjTjzwWuLDsM=</P><Q>0jat9uBZUDVQJOz8wSD4n0YffmU=</Q><G>epyQJV9QGsh845z+QD8v1GpipREXn+UXmkiW9vPs3BVGGM0ghZFDduArfMn8wZYX4ByIOU1t0tLsZ00Aac1Wu3ZB+X1ccY6E5AVeRLDialis4YyYPjO0wdmZezm9feOSg866450wknur/k9Jz3VnnOC/lrd1tAsIYRajmYCDMZs=</G><Y>MfdvjimBnuxe3s0+xRMcF2BRokqDANzwrMxMJCfmr9Y/Xn+a+uii4/S56169uUryU6hKcuWVoYdSFo7upLDSl8mVn37gg/N78m942PBh2qFRBCLLaGtkV81dRxSxsqln54AlBx5XrfHbAmAGkfAuIA11EeQcJSCt75qkliJNbGw=</Y><Seed>8DxESgmqPh6mI5OkwmQBDiiIrHc=</Seed><PgenCounter>A9M=</PgenCounter></DSAKeyValue>

Private Key

<DSAKeyValue><P>gSFAXq2fbk0P+6y1G6aYXlUPdESfs42kaF/v4pfkt9sNx1bx8Ni4IVzXdgtDLKhIpL9cv6Ho0pEM5qCVZ0oY8QZJpt8PC4ZEiCEgWFGLLLooriZmJPwsEQtcjB/sz4lvvO9oFrLnrYS16e3FCriImDTBVtv3TVptjTjzwWuLDsM=</P><Q>0jat9uBZUDVQJOz8wSD4n0YffmU=</Q><G>epyQJV9QGsh845z+QD8v1GpipREXn+UXmkiW9vPs3BVGGM0ghZFDduArfMn8wZYX4ByIOU1t0tLsZ00Aac1Wu3ZB+X1ccY6E5AVeRLDialis4YyYPjO0wdmZezm9feOSg866450wknur/k9Jz3VnnOC/lrd1tAsIYRajmYCDMZs=</G><Y>MfdvjimBnuxe3s0+xRMcF2BRokqDANzwrMxMJCfmr9Y/Xn+a+uii4/S56169uUryU6hKcuWVoYdSFo7upLDSl8mVn37gg/N78m942PBh2qFRBCLLaGtkV81dRxSxsqln54AlBx5XrfHbAmAGkfAuIA11EeQcJSCt75qkliJNbGw=</Y><Seed>8DxESgmqPh6mI5OkwmQBDiiIrHc=</Seed><PgenCounter>A9M=</PgenCounter><X>ZN67VkaNCRolYpQDVKCOeNYK88M=</X></DSAKeyValue>

OK, the private key is ready. How can I change the public key in postsharp. SDK. extensibility. Licensing. cryptoutilities?

Copy postsharp. settings. dll, open the vs command line, and decompile it into il code using ildasm.

ildasm PostSharp.Settings.dll /output= PostSharp.Settings.il

Find the code for setting the public key in the generated il code (search. class public abstract auto ANSI sealed postsharp. SDK. extensibility. licensing. cryptoutilities), change the Public Key (both) to the generated public key to save the Il

Use ilasm to generate DLL files

ilasm PostSharp.Settings.il /dll

Now, the new public key has been written to postsharp. settings. dll.

Copy the new postsharp. settings. DLL to the postsharp installation directory to overwrite the original one. Open postsharp registration and enter the registration code generated above. Next, a pleasant surprise

Success!

Download is not provided, because you know

Postsharp 4.0 registration machine implementation process

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.