Talking about IM software business knowledge-Asymmetric encryption, RSA algorithm, digital signature, public key, private key

Source: Internet
Author: User
Tags decrypt asymmetric encryption

Overview

First look at the concept: RSA algorithm: 1977 by Ron Rivest, Adi Shamirh and Lenadleman invented. RSA is the name of the three people who were taken from them.

The algorithm is based on a number theory: it is easy to multiply two large primes, but it is difficult to factorization the results of this product, so the product can be exposed as a public key. This algorithm can resist all password attacks that are known at the moment.

RSA algorithm is an asymmetric algorithm, the algorithm needs a pair of keys. Use one of the encryption. Need to use another talent to decrypt. When we are doing RSA encrypted communication. The public key is placed on the client and the private key is left in the server.

RSA Asymmetric Encryption algorithm can verify the legitimacy of both client and server, security level is very high.

It's the most important encryption algorithm on Earth right now.

How to generate public and private keys

1. Select two prime p=17. q=11
2. Calculate the flight n = 17*11 = 187
3. Compute Euler function φ (n) = (p-1) (q-1) = 160 for N.


4. Select E, so that E and φ (n) are mutual and less than φ (n). Select e=7 (the actual application in which n is a maximum number.) Commonly used 65537)

5. Calculate d. Makes the de mod 160=1 and D < 160. The correct value is 161, which is due to the 10*16+1

This will result in the public key pu={7,187} private key pr={23,187} references here

How to encrypt and decrypt?for a certain plaintext m and ciphertext C, encryption and decryption have the following form:
Encryption: C=me mod n
Decryption: M=CE mod n

Assume that the public key pu=7,187 the private key pr=23,187. Bring into the equation for example with what you see:


For encryption, you need to calculate c = 887 MoD 187.

Using the properties of the modulo operation, the calculation is as follows:

887mod187 = [(884 mod 187) * (882 mod 187) * (881MOD)] MoD 187

881 MoD 187 = 88

882 mod 187 = 7744 MoD 187 = 77

884 mod 187 = 59969536 MoD 187 = 132

887mod187 = (88*77*132) mod 187 = 89432 MoD 187 = 11

For decryption. Calculate m = 1123 MoD 187;

M = 1123 MoD 187 = [(111 mod 187) * (mod 187) * (mod 187) * (118 mod 187) * (118 mod 187)] MoD 187

111 MoD 187 = 11

187 MoD = 121

187 mod = 14641 MoD 187 = 55

118 MoD 187 = 214 258 881 MoD 187 = 33

M = 1123 MoD 187 = (11*121*55*33*33) mod 187 = 79720245 MoD 187 = 88

The reliability of RSA

Recalling the above key generation step, there are altogether six numbers:
P
Q
N
φ (n)
E
D
Of these six numbers. The public key is used to two (n and e). The remaining four figures are not public. The most critical of all is D, since N and D make up the private key, and once d leaks, it is equal to the private key leak.
So. Is it possible to derive a d in the case of known N and e?
(1) ed≡1 (modφ (n)). Just have to know E and φ (n). Ability to figure out D.


(2) φ (n) = (p-1) (q-1). Just have to know P and Q, the ability to calculate φ (n).
(3) N=pq.

Only the n factor decomposition, the ability to calculate p and Q.
Conclusion: Assuming that n can be decomposed by a factor, D can be calculated, which means that the private key is cracked.
But. The factorization of large integers is a very difficult thing to do. For now, there are no other effective ways to find anything but brute force.

Wikipedia writes:
"The difficulty of factoring the maximal integers determines the reliability of the RSA algorithm." Other words. The more difficult the factorization of a large integer, the more reliable the RSA algorithm.


If someone finds a high-speed factorization algorithm. Then RSA's reliability will be extremely degraded. But the likelihood of finding this algorithm is very small. Today only a short RSA key can be brute force.

Until 2008, there was no reliable way to attack the RSA algorithm in the world.


  Only if the key length is long enough, the information encrypted with RSA is not actually broken. "

Digital signature, private key encryption. Public key decryption illustrates how to digitally sign with a private key:
Digital Signature Process:1. Get the message digest value
2. Der Data Encoding for Abstracts
3. RSA private key Encryption
4. The conversion of the byte string into the string.


Here's the test.

For the RSA algorithm, the key encryption can be decrypted with a different key, regardless of the side of the key, which is explained from another angle, in fact the public key and private key are relative. Release one of the keys out. The other one naturally becomes the private key.

An example of an asymmetric encryption case is our project. Take a picture of the sequence and look at it accordingly.
Precondition client and server negotiate well, generate a pair of public key-private key, client writes dead to code, call Buildin-key1. The client sends Cnonce to Server,server to generate signature with a private key pair (cnonce+public-key+snonce) for digital signature generation. The server answers the snonce, Public-key, and signature to Client2. The client verifies the server's response.

The verification process is: Buildin-key calls the Seckeyrawsign function pair (cnonce+public-key+snonce) for validation. 3. Client uses Public-key (Dynamic public key. Because this is more secure), the Password digest, snonce, is encrypted.

4. After the server is received, the decrypted data gets a password digest that matches the password digest and snonce correctly. The second step is to authenticate the server to the client, and the fourth step is to validate the client with the server. Introduction to the iOS platform RSA

Our common certificate can be seen as a public key, and the certificate includes the public key and some other information. Iosclient encryption and decryption. First we need to import security.framework, in iOS, we focus on four functions.
Seckeyencrypt: Encrypts the data using the public key.


Seckeydecrypt: Decrypts the data using the private key.
seckeyrawverify: Use the public key to validate digital signatures and data to verify the source legitimacy of the data.
seckeyrawsign: Use the private key to digest the data and generate a digital signature.
From these functions, we can see that the public key can do two things: Encrypt the data, and the server side of the data sent to the signature authentication. But suppose you want to be the same as I thought before. To use the public key to decrypt the data, there is no self-bringing API.

If you want to encrypt data using the private key on the server side, and then decrypt it using the public key in the client, it seems impossible to encrypt the interactive data in such a way. In fact, it should be, the public key is public. At the same time, RSA is a large number of operations. The performance of the algorithm is relatively poor, assuming a large amount of data encryption and decryption. For iOS. is certainly not appropriate.


The Bank U Shield u shield is a miniature electronic board with storage computing function, which should have an encrypted storage part for writing the certificate, but this storage part cannot be read by the external USB interface, but the MPU can read and decrypt (the details are unclear), this function is realized by physical circuit. Assumed by the hardware anatomy. You should be able to read the encrypted content, but still cannot decrypt it. There should also be a micro processor, MPU. Used to perform cryptographic algorithms and respond to external USB interface directives, which are the core components.


U Shield working process: when the net silver responds to user operation, the whole instruction information is packaged and fed into U shield via USB port. The U-Shield is signed internally by the MPU using the certificate (private key) and then sent out.

It is then transferred by IE to the server via SSL. When the server receives the instruction package, it is signed and authenticated by the public key retained by the user on the key distribution server, and the command is run if the authentication is correct.

Theoretically speaking. After generating a pair of public and private key pairs through two large primes, the Bank Key distribution management system should send the private key to the user, write the U shield, and then delete the two large primes and the private key on the server. Only the public key is retained.

However, the actual project process. There are many security risks:
Hidden trouble a process in which the private key is sent to the user. May be intercepted by a third party. Although this process uses an SSL channel. And by the bank's password download.

But so this user's computer is controlled by people. IE is tampered with, or there is the possibility of being stolen. Just download the certificate is a one-time action, two years only once.
Hidden trouble two because large prime numbers are difficult to find, it is not possible to do it once in project implementations: that is, a large number of public and private key pairs are generated by the same pair of primes, and this pair of large primes is retained on the server. On the one hand, there may be correlation between the public and private key pairs of multiple common-mode. There is one more aspect. Assuming someone has access to a large number of prime numbers retained on the server, it is very easy to recover the private key from the user's public key.

Individual push, the bank should be through a large prime pool, randomly pick two to generate a key pair.

And this large prime pool is regularly replaced and very tightly supervised by this key distribution server.
At last

Decoding RSA is thought to be one of the hardest topics in all computer science. So. Suppose you invented a way to break a huge number into prime numbers at a high speed, not only to invade the Swiss bank's account system, but also to get a Turing award!

Talking about IM software business knowledge-Asymmetric encryption, RSA algorithm, digital signature, public key, private key

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.