Encryption and decryption

Common encryption and decryption algorithms and their characteristics:

    1. One-way encryption: MD5, SHA;
    2. Symmetric encryption: DES, AES;
    3. Asymmetric encryption: RSA



    With the rapid development of e-commerce, information security has become a focus issue One, especially online payment and online banking have more prominent requirements for information security. In order to carry out safe e-commerce activities on the Internet, Public Key Infrastructure (PKI, Public Key Infrastructure) has gradually been widely used at home and abroad. Do we really need PKI and what is PKI for? Let’s analyze this problem step by step through a case: A wants to send a contract document to B who is far abroad through the Internet. This contract document is very important to both parties, there should be no mistakes, and this document must not be used by other people. know its content. How can I achieve the secure sending of this contract?
Question 1: The most natural idea is that A must encrypt the file to ensure that its contents cannot be viewed by others. Then, what encryption technology should be used to make the contract transmission both secure and fast?
    Some mature symmetric encryption can be used Algorithms such as DES, 3DES, RC5, etc. encrypt files. Symmetric encryption uses symmetric encryption technology, which is characterized by the use of the same key for file encryption and decryption, that is, the encryption key can also be used as a decryption key. This method is called a symmetric encryption algorithm in cryptography.
Question 2: If a hacker intercepts the file, can the same algorithm be used to decrypt the file?
    No, because both encryption and decryption require two components: the encryption algorithm and the symmetric key. The encryption algorithm requires a symmetric key to decrypt, and the hacker does not Don't know this key.
Question 3: Since the hacker does not know the key, how can B get his key securely? It is notified by phone that if the phone is listened to, the key is sent to B through the Internet, which may be intercepted by hackers. What should I do?
    The method is to encrypt the symmetric key with an asymmetric key algorithm and transmit it. Unlike symmetric encryption algorithms, asymmetric encryption algorithms require two keys: a public key (Public Key) and a private key (Private Key). The public key and the private key are a pair. If the data is encrypted with the public key, only the corresponding private key can be used to decrypt it; if the data is encrypted with the private key, only the corresponding public key can be used to decrypt the data. . Because encryption and decryption use two different keys, this algorithm is called an asymmetric encryption algorithm (public/private keys can be generated by specialized software). Party A and Party B each have a pair of public/private keys, the public key can be transmitted on the Internet, and the private key is kept by itself. In this way, A can encrypt the symmetric key in the symmetric encryption algorithm mentioned in Problem 1 with B's public key. Even if the hacker intercepts this key, the hacker will not be able to unlock the symmetric key because the hacker does not know B's private key, and therefore cannot decrypt the ciphertext. Only B can decrypt the ciphertext.
Question 4: Since A can encrypt its symmetric key with B's public key, why not encrypt its file directly with B's public key? This is not only simple, but also saves the step of encrypting the file with a symmetric encryption algorithm?
    You can't do that. Because the asymmetric encryption algorithm has two disadvantages: the encryption speed is slow, 10 to 100 times slower than the symmetric encryption algorithm, so it can only be used to encrypt small data (such as symmetric keys), and the resulting ciphertext will become longer after encryption. Therefore, a symmetric encryption algorithm is generally used to encrypt its files, and then an asymmetric algorithm is used to encrypt the symmetric key used by the symmetric algorithm.
Question 5: If the hacker intercepts the ciphertext, he also intercepts the symmetric key encrypted with the public key. Since the hacker does not have B's private key, he cannot decrypt the symmetric key, but if he encrypts a copy with the symmetric encryption algorithm Fake file, and encrypt a symmetric key of the fake file with B's public key, and send it to B, B will think that it is the file sent by A, and will decrypt the fake file with its private key, and read its content happily , but I don't know it has been replaced. In other words, B does not know that this is not sent to him by A, what should I do?
    The answer is to prove its identity with a digital signature. Digital signature is to extract a digest from a large block of data through a hash algorithm, such as MD5, SHA-1 and other algorithms. From this summary, no original text can be recovered by hashing algorithm, that is, the obtained summary will not reveal any information of the original plaintext, but if the original information is modified in any way, the obtained summary will definitely be different. Therefore, A can perform a hash algorithm on the file to get the digest, and encrypt it with his own private key (because the asymmetric algorithm is reversible, that is, the file encrypted by the public key can be decrypted with the private key, and vice versa), so that even if a hacker intercepts it, it is useless. Because the hacker won't get any information from the digest, but B is different, he can decrypt it with A's public key and get the digest (if the digest can be decrypted with A's public key, it means that the digest must be sent by A, Because only A's public key can decrypt the information encrypted with A's private key, and A's private key is known only by A), and the same hash algorithm is performed on the received file (decrypted contract file), By comparing whether the digests are the same, you can know whether the file has been tampered with (because if the digests are the same, the information has not been changed, which is the characteristic of the hash algorithm). This not only solves the problem of proving the identity of the sender, but also solves the problem of whether the file has been tampered with.
Question 6: Is it foolproof to encrypt its file with a symmetric encryption algorithm, encrypt its symmetric key with an asymmetric algorithm, and prove the sender's identity and the correctness of its information through a hash algorithm?
    The answer is no. The problem is that B is not sure that the so-called public key of A that he uses must belong to A. The solution is to use a digital certificate to bind the public key and the owner of the public key.
    A digital certificate is a file that is digitally signed by a certificate authority and contains the public key owner information and public key. It is a series of data that identifies the identity information of the communication parties in network communication. In a way, its role is similar to the driver's license or the ID card in daily life, and people can use it to identify each other's identity in communication.
    The simplest certificate contains a public key, name, and a digital signature from a certificate authority. In general, the certificate also includes the validity time of the key, the name of the issuing authority (certificate authority), the serial number of the certificate and other information. It is issued by an authority, the CA, also known as the Certificate Authority. As a trusted third party in e-commerce transactions, the CA is responsible for verifying the validity of the public key in the public key system. The CA center issues a digital certificate to each user who uses the public key. The function of the digital certificate is to prove that the user listed in the certificate legally owns the public key listed in the certificate. The digital signature of the CA agency makes it impossible for attackers to forge and tamper with the certificate. The CA is the core of the PKI and is responsible for managing the certificates of all users (including various applications) under the PKI structure. Together, verify the user's identity online.
    Because the digital certificate is public, like a public phone book, in practice, the sender (ie, A) will send a copy of his own digital certificate together with the ciphertext, digest, etc. to the receiver (ie. B), and B checks the validity of this certificate by verifying the signature of the authority on the certificate (just use the public key of that trusted authority to verify the signature on the certificate), if the certificate checks everything Normal, then it can be trusted that the public key contained in the certificate really belongs to the person listed in the certificate (ie, A).
Question 7: So far it seems safe. However, there are still security loopholes. For example, although A sends the contract document to B, A refuses to admit that he has signed the document at the moment indicated by the signature (a digital signature is equivalent to the text signature of a written contract), and sends this document to B. What if the fault is attributed to the computer and the contract is not fulfilled?
    The solution is to use a trusted clock service (provided by an authority) that jointly signs the file by a trusted time source and the signer of the file. In a written contract, the date on which the document is signed is as important as the signature to prevent the document from being forged and tampered with (for example, the contract generally stipulates that it will take effect on the date of the document being signed). In electronic files, since the user's desktop time can be easily changed (inaccurate or artificially changed), the timestamp generated by this time cannot be trusted, so a third party is required to provide a timestamp service (Digital Timestamp Service (DTS) is Online security services, provided by specialized agencies). This service provides security protection of the time of publication of electronic documents.
    The process of time stamp generation is as follows: the user first encrypts the file that needs to be time stamped with hash code to form a digest, and then sends the digest to DTS. DTS adds the date and time information of the received file digest before adding the file digest. Encrypted (digitally signed) and sent back to the user. Therefore, the time-stamp is an encrypted credential document, which includes three parts: the digest of the document to be time-stamped, the date and time when DTS received the document, and the digital signature of DTS. Since the credible time source and the signer of the document jointly sign the document, thereby preventing the possibility of time fraud by the party that signed the document (ie, the first party), it has non-repudiation.
Question 8: With the digital certificate binding the public/private key and the identity, and the authority providing the clock service to make it non-repudiation, is it foolproof? No, there are still problems. B still cannot prove that the other party is A, because it is entirely possible that someone else has stolen A's private key (for example, someone else is using A's computer when A is not using A's computer), and then uses A's identity to send information to B. How to solve this?
    Solution It uses technologies such as strong passwords, authentication tokens, smart cards, and biometrics to authenticate users who use private keys to determine that they are legitimate users of private keys.
    Before tackling this problem, let's take a look at how currently implemented PKI-based authentication generally works. Taking a browser or other application that registers for a certificate as an example, a key store will be created when the key is first generated, and the browser user will be prompted to enter a password, which will be used to construct and protect the certificate. Encryption key required for key storage. If the key store is only weakly password protected or not password protected at all, then anyone with access to the computer's browser can access those private keys and certificates. In this scenario, how can it be possible to trust the identity created by PKI? Because of this, a strong PKI system must be built on the basis of strong authentication of the owner of the private key. Now the main authentication technologies are: Strong passwords, authentication tokens, smart cards, and biometrics (such as fingerprints, eye masks, etc.).
    Take the authentication token as an example: Assuming that the user's private key is stored in the encrypted container of the backend server, to access the private key, the user must first use the authentication token to authenticate (such as the user entering the account name, the passcode and PIN displayed on the token) etc.), if the authentication is successful, the user's encrypted container is downloaded to the user's system and decrypted.
By solving the above problems, the demand for securely sending files is basically satisfied. To summarize this process, the whole sending process for A is as follows:
1. Create a symmetric key (generated by the corresponding software, and it is one-time), use it to encrypt the contract, and wrap the symmetric key with B's public key.
2. Create a digital signature, perform a hash algorithm (such as MD5 algorithm) on the contract and generate the original digest, A encrypts the digest with his own private key (the public/private key can be created by himself or provided by the CA).
3. Finally, A sends the encrypted contract, packaged key, encrypted digest, and A's digital certificate (issued by the authority CA) to B.
After receiving the encrypted file, B needs to complete the following actions:
1. After receiving, decrypt with B's private key to obtain the symmetric key, and use the symmetric key to unlock the encrypted contract to obtain the contract plaintext.
2. Obtain the public key belonging to A through A's digital certificate, and use it to unlock the digest (called digest 1).
3. Use the same hashing algorithm as the sender to create a digest of the decrypted contract (called digest 2).
4. Compare summary 1 and summary 2. If they are the same, it means that the information has not been tampered with and comes from A.
    The process of sending information between A and B seems to be not complicated, but in fact it consists of many basic components, such as: symmetric/asymmetric key cryptography, digital certificates, digital signatures, certificate authority (CA), and public key security policies Etc., the most important and complex of these is the construction of the certificate authority (CA).
The certificate and signature are emphasized here: the
    certificate is actually for the asymmetric encryption algorithm (public key encryption), and the general certificate includes three parts: the public key, the name, and the digital signature. A certificate is like an ID card, and a certificate authority (ca) is like a public security bureau, whose responsibility is to manage the user's certificate, that is, an ID card. For example, my public key is FrankKey, and my name is Frank Xu Lei. The Public Security Bureau can register me, but how can I be distinguished from other Frank XuLei? So the Public Security Bureau (Certificate Authority) used my name and key to make a combination, and then used a hash algorithm to get A string of values ​​to identify my uniqueness. This value is my ID number, which is the digital signature (message digest) in the certificate. At the same time, in order to prevent hackers from imitating the digital certificate, the issuer of the digital certificate uses its own private The digital signature is encrypted with the key, so that the network transaction entity using the digital certificate can decrypt and verify with the public key of the certificate issuer. (That is, the purpose of the digital signature is to prove that your identity is indeed your real self and not someone else, so you need to encrypt it with your own private key, and let the user use the public key for decryption and verification, thus technically preventing forging yourself. hacker.)
    Suppose a friend writes to me, he can go to the public security bureau (certificate authority) to find my ID card (certificate). It includes my personal information, which guarantees that this public key is mine. Then he encrypted the new one and mailed it to me. Even if others open my letter, because there is no key to decrypt it, they cannot read the content of my letter. This ensures information security.
    So encryption does not necessarily require a certificate, it depends on your specific needs for data security. Generally, large e-commerce sites have their own specific certificates. The more famous certificate management organization is VeriSign (it can be said to be the ID card authority on the Internet). Businesses can apply for registration and it will generate specific signatures for applicants. If necessary for our own internal enterprise applications, we can establish a private certificate server within the enterprise LAN to generate and manage certificates. In fact, X.509 is an international standard that defines the format and distribution of certificates (equivalent to a specification for making ID cards) formulated by the International Telecommunication Union (ITU-T). In order to provide public network user directory information services, and specify the certificate syntax and data interface widely used in the entity identification process, X.509 calls it a certificate, or a form of identity card, similar to our current second-generation An ID card, also a type of ID card, is produced according to specific standards. In addition, when the certificate is used, there is a limit on the validity period, which is the same as the 10-year validity period of our ID card. Certificates can also have an expiration date.

Attachment: Introduction to the Working Principle of USB Shield
1. What is USB Shield
     USB key, namely the customer certificate USBkey launched by ICBC in 2003 and obtained a national patent, is a high-level security tool provided by ICBC for online banking business. It looks like a U disk, like a shield, protecting your online banking funds at all times.
From a technical point of view, U-Shield is a tool for electronic signature and digital authentication in online banking. It has a built-in micro smart card processor and uses 1024-bit asymmetric key algorithm to encrypt, decrypt and digitally sign online data to ensure the integrity of online transactions. Confidentiality, authenticity, integrity and non-repudiation
2. How it works
    USB shield is also used as a mobile digital certificate, which stores your personal digital certificate and cannot be read. Likewise, banks keep track of your digital certificates.
When you try to conduct an online transaction, the bank will send you a string A, which is encrypted by combining the time string, address string, transaction information string, and anti-replay attack string. Your USB shield will Perform an irreversible operation on the string A according to your personal certificate to obtain the string B, and send the string B to the bank, and the bank also performs the irreversible operation at the same time. , the transaction can be completed, if it is inconsistent, you are considered illegal, and the transaction will fail. (Theoretically, different strings A will not result in the same string B, that is, a string A corresponds to a unique string B; but strings B and A cannot derive your digital certificate, and U The shield is unreadable, so no one can obtain your digital certificate. And the bank will send different anti-replay strings (random strings) and time strings every time, so when a transaction is completed, just The sent B string is no longer valid. To sum up, in theory, the U shield is absolutely safe. Note that the theoretical probability of forgery is about 1/80 of 2, but if there is a deformation like The kind of DNAbasecomputer in King Kong.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326720996&siteId=291194637