Implementation of non-symmetric encryption and digital signature RSA algorithm in Silverlight

Source: Internet
Author: User
Tags integer silverlight asymmetric encryption

RSA algorithm is the first algorithm that can be used both for data encryption and digital signature. It is easy to understand and operate, but also very popular. Its security is based on the difficulty of large integer factor factorization, and the large integer factorization problem is a famous problem in mathematics, so far there is no effective method to solve it, so the security of RSA algorithm can be ensured.

By the current beta release of SILVERLIGHT4, no asymmetric encryption and digital signature-related algorithms are still available in Silverlight. Algorithms such as RSA, provided in the. NET framework, are implemented through the relevant APIs provided by the operating system and are not portable to Silverlight. It is therefore difficult to implement a robust point of Silverlight Pure client registration verification algorithm. These days, I've written a Silverlight. The available RSA algorithm, using asymmetric encryption and digital signature makes the Silverlight pure client registration verification algorithm robust. About the implementation of the RSA algorithm available under Silverlight, recorded in the following, welcome everyone to Pat Bricks.

RSA algorithm implementation is divided into three parts: including the generation of public and private keys, asymmetric encryption and decryption, digital signature and verification, the following will be introduced one by one the principle of RSA algorithm and my implementation methods.

1, the creation of public and private keys

Randomly choose two large primes p, q,p not equal to q, compute n = p * Q.

Randomly select an integer e, satisfying E and (p–1) * (q–1) coprime. (Note: E is easy to choose, such as 3, 17, 65537, and so on.) e defaults to 65537 in the. NET Framework

Using Euclid algorithm to compute decryption key D, satisfy

E * d≡1 (mod (p-1) * (q-1))

where N and D are also coprime.

where E and n are the public keys, and D and N are the private keys. P, q Destroy.

In the. NET Framework's RSA algorithm, E corresponds to rsaparameters.exponent;d corresponding rsaparameters.d;n corresponding to rsaparameters.modulusexponent. Net The RSA algorithm in the framework uses a 1024-bit long key by default. The public and private keys are implemented using the RSACryptoServiceProvider of the. NET framework to generate public key XML files and private key XML files. The program that generates the public and private key XML files is not itself a Silverlight program.

Code

RSACryptoServiceProvider rsa = new  RSACryptoServiceProvider();
     //生成公钥XML字符串
     string publicKeyXmlString = rsa.ToXmlString(false);
     //生成私钥XML字符串
     string privateKeyXmlString = rsa.ToXmlString (true);

The public and private keys are imported from the generated public key XML file and the private key XML file.

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.