📚 Symmetric vs Asymmetric Encryption: Principles and Differences | 对称与非对称加密:原理与区别
Encryption is the process of converting readable data (plaintext) into an unreadable format (ciphertext) to protect its confidentiality. Understanding the difference between symmetric and asymmetric encryption is a core requirement in the CIE Computer Science syllabus, as it underpins modern secure communication.
加密是将可读数据(明文)转换为不可读格式(密文)以保护其机密性的过程。理解对称加密与非对称加密的区别是 CIE 计算机科学考纲中的核心要求,因为它是现代安全通信的基础。
1. Basic Concepts of Encryption | 加密的基本概念
An encryption system always involves four elements: plaintext, ciphertext, an encryption algorithm, and a key. The key is a piece of secret information that controls how the algorithm transforms data. Without the correct key, decryption is computationally infeasible.
加密系统始终包含四个要素:明文、密文、加密算法和密钥。密钥是控制算法如何转换数据的一段秘密信息。没有正确的密钥,解密在计算上是不可行的。
There are two main categories of encryption algorithms: symmetric encryption, which uses a single shared key, and asymmetric encryption, which uses a pair of mathematically related keys (public and private). These two approaches solve different problems and are often combined in real-world systems.
加密算法主要分为两类:对称加密使用单一共享密钥,非对称加密使用一对数学相关的密钥(公钥和私钥)。这两种方法解决不同的问题,在实际系统中经常结合使用。
2. Symmetric Encryption: The Single-Key Model | 对称加密:单密钥模型
In symmetric encryption, the same key is used for both encryption and decryption. The sender encrypts the plaintext with key K, producing ciphertext; the receiver decrypts the ciphertext with the same key K, recovering the original plaintext.
在对称加密中,同一个密钥既用于加密也用于解密。发送方使用密钥 K 加密明文,生成密文;接收方使用相同的密钥 K 解密密文,恢复原始明文。
This system is fast and efficient because symmetric algorithms require relatively low computational power. Examples include the Caesar cipher for historical context, and modern algorithms such as AES (Advanced Encryption Standard) and DES (Data Encryption Standard).
该系统的优点是速度快、效率高,因为对称算法需要的计算能力相对较低。历史背景的例子包括凯撒密码,现代算法包括 AES(高级加密标准)和 DES(数据加密标准)。
C = Eₖ(P) and P = Dₖ(C)
Here, Eₖ denotes encryption with key K, and Dₖ denotes decryption with the same key K. The security of this model depends entirely on keeping K secret. If an attacker obtains K, the entire communication is compromised.
这里,Eₖ 表示使用密钥 K 加密,Dₖ 表示使用同一个密钥 K 解密。该模型的安全性完全依赖于对 K 的保密。如果攻击者获得 K,整个通信就会被破解。
3. The Key Distribution Problem | 密钥分发问题
The main weakness of symmetric encryption is the key distribution problem. Before two parties can communicate securely, they must both possess the same secret key. If they are geographically separated, how do they share it securely?
对称加密的主要弱点是密钥分发问题。在双方能够安全通信之前,他们必须同时拥有相同的秘密密钥。如果两地相距遥远,他们如何安全地共享密钥?
Options include physical delivery, a trusted courier, or an out-of-band channel. These methods are slow, expensive, and still vulnerable to interception. For n users who all need to communicate with each other, n(n-1)/2 distinct keys are required, which becomes unmanageable for large groups.
方法包括物理递送、可信信使或带外信道。这些方式速度慢、成本高,并且仍然存在被截获的风险。对于需要互相通信的 n 个用户,需要 n(n-1)/2 个不同的密钥,当群体规模变大时,这变得难以管理。
- Example: For 10 users, 10 × 9 / 2 = 45 keys must be exchanged securely.
- 示例:对于 10 个用户,需要安全交换 10 × 9 / 2 = 45 个密钥。
4. Asymmetric Encryption: The Key-Pair Model | 非对称加密:密钥对模型
Asymmetric encryption, also called public-key cryptography, uses two different but mathematically related keys: a public key and a private key. The public key is freely distributed to anyone, while the private key is kept secret by its owner.
非对称加密,也称为公钥密码学,使用两个不同但数学相关的密钥:公钥和私钥。公钥可以自由分发给任何人,而私钥由所有者保密保管。
Data encrypted with the public key can only be decrypted with the corresponding private key, and vice versa. This design removes the key distribution problem entirely, because the public key does not need to be secret.
用公钥加密的数据只能用相应的私钥解密,反之亦然。这种设计彻底解决了密钥分发问题,因为公钥不需要保密。
C = E_{pk}(M) and M = D_{sk}(C)
The sender uses the recipient’s public key pk to encrypt, and only the recipient who holds the private key sk can decrypt. Even if everyone on the network knows pk, they cannot decrypt the message without sk.
发送方使用接收方的公钥 pk 加密,只有持有私钥 sk 的接收者才能解密。即使网络上的所有人都知道 pk,没有 sk 也无法解密消息。
5. RSA: The Most Famous Asymmetric Algorithm | RSA:最著名的非对称算法
RSA (Rivest-Shamir-Adleman) is the most widely used asymmetric encryption algorithm. Its security is based on the mathematical difficulty of factoring the product of two large prime numbers.
RSA(里维斯特-沙米尔-阿德尔曼)是使用最广泛的非对称加密算法。其安全性基于将两个大素数的乘积进行因数分解的数学难度。
The key generation process begins with selecting two large distinct primes p and q. Their product n = p × q forms part of both the public and private keys. A public exponent e is chosen such that 1 < e < φ(n), where φ(n) = (p-1)(q-1), and e is coprime to φ(n). The private exponent d is then computed as the modular inverse of e modulo φ(n).
密钥生成过程首先选择两个大的不同素数 p 和 q。它们的乘积 n = p × q 构成公钥和私钥的一部分。选择公钥指数 e,满足 1 < e < φ(n),其中 φ(n) = (p-1)(q-1),且 e 与 φ(n) 互质。然后计算私钥指数 d,它是 e 关于模 φ(n) 的乘法逆元。
Encryption: C = Mᵉ mod n
Decryption: M = Cᵈ mod n
Because n is extremely large (typically 2048 bits or more), and factoring it requires exponential time, the message remains secure. As of current computing power, 2048-bit RSA is considered practically unbreakable.
由于 n 非常大(通常为 2048 位或更大),对其分解需要指数级时间,因此消息保持安全。在当前计算能力下,2048 位 RSA 被公认为实际上不可破解。
6. Symmetric vs Asymmetric: Performance Comparison | 对称与非对称:性能比较
Symmetric encryption is significantly faster than asymmetric encryption. Modern CPUs can encrypt AES data at several gigabytes per second, whereas RSA is thousands of times slower and limited to small data blocks. For this reason, asymmetric encryption is rarely used to encrypt large messages directly.
对称加密的速度远快于非对称加密。现代 CPU 每秒可以加密数 GB 的 AES 数据,而 RSA 慢数千倍,并且只能处理小数据块。因此,非对称加密很少直接用于加密大消息。
Another key difference is key length. AES-128 uses 128-bit keys and provides strong security. RSA requires at least 2048 bits to achieve a comparable level of security. Longer keys mean more storage and higher computational cost.
另一个关键区别是密钥长度。AES-128 使用 128 位密钥即可提供强安全性。RSA 需要至少 2048 位才能达到相当的安全水平。更长的密钥意味着更多的存储需求和更高的计算成本。
| Property | Symmetric (AES) | Asymmetric (RSA) |
|---|---|---|
| Key relationship | Same key for both operations | Public key and private key pair |
| Key length | 128, 192, 256 bits | 2048 or 4096 bits |
| Speed | Very fast | Slow |
| Key distribution | Difficult; needs secure channel | Easy; public key is public |
| Use case | Bulk data encryption | Key exchange, digital signatures |
Property | Symmetric | Asymmetric
Additionally, symmetric algorithms are less vulnerable to certain mathematical attacks, while asymmetric algorithms rely on hard mathematical problems such as factoring or discrete logarithms, which may be weakened in the future by quantum computers.
此外,对称算法对某些数学攻击的抵抗性更强,而非对称算法依赖诸如因数分解或离散对数等困难数学问题,未来量子计算机可能会削弱这些问题的难度。
7. The Role of the Caesar Cipher in Understanding Symmetry | 凯撒密码在理解对称性中的作用
The Caesar cipher is one of the earliest known encryption techniques. It shifts each letter in the plaintext by a fixed number of positions. For example, with a shift of 3, ‘A’ becomes ‘D’. The same shift value is used for decryption in the opposite direction.
凯撒密码是最早已知的加密技术之一。它将明文中的每个字母按照固定位数进行移位。例如,位移为 3 时,’A’ 变为 ‘D’。解密时使用相同的位移值向相反方向移动。
This is a classic example of symmetric encryption because the encryption key equals the decryption key. Although trivial to break, it illustrates how the security of a symmetric system resides entirely in the secrecy of the key, not the algorithm.
这是对称加密的典型示例,因为加密密钥等于解密密钥。虽然很容易被破解,但它说明了对称系统的安全性完全取决于密钥的保密性,而不是算法本身。
Also: Vigenère cipher, DES, 3DES, AES
The Vigenère cipher uses a keyword to vary the shift per character, making it more resistant to frequency analysis than the Caesar cipher. DES was adopted as a federal standard in 1977 but its 56-bit key is now too short. AES replaced it after a public competition.
维吉尼亚密码使用关键字对每个字符进行不同的移位,比凯撒密码更能抵抗频率分析。DES 于 1977 年被采纳为联邦标准,但其 56 位密钥如今已过短。AES 在公开竞赛后取代了 DES。
8. Hash Functions, Digital Signatures and Non-Repudiation | 哈希函数、数字签名与不可否认性
Asymmetric encryption enables a crucial feature called digital signatures. Instead of encrypting a message for confidentiality, the sender encrypts a hash of the message with their private key. Any receiver can decrypt it with the sender’s public key, verifying that the message truly came from that sender.
非对称加密实现了一项关键功能,即数字签名。发送方不直接加密消息本身,而是用其私钥加密消息的哈希值。任何接收者都可以用发送方的公钥解密,从而验证消息确实来自该发送者。
This process provides two guarantees: authentication (the sender is who they claim to be) and non-repudiation (the sender cannot deny having sent it). A hash function such as SHA-256 converts any message into a fixed-length digest, and even a tiny change in input completely changes the digest.
这个过程提供两种保证:身份认证(发送者确实是声称的人)和不可否认性(发送者无法否认已发送)。哈希函数(如 SHA-256)将任何消息转换为固定长度的摘要,即使输入发生微小变化,摘要也会完全改变。
Sign: H = Hash(M); S = E_{sk}(H)
Verify: H’ = D_{pk}(S); check H’ = Hash(M)
This is widely used in software distribution, document signing, and blockchain transactions. It is important to note that digital signatures do not provide confidentiality; they provide integrity and authenticity.
这广泛应用于软件分发、文件签名和区块链交易中。需要明确的是,数字签名不提供机密性;它们提供完整性和真实性。
9. The Key Exchange Problem Solved: Diffie-Hellman and Hybrid Systems | 密钥交换问题的解决:Diffie-Hellman 与混合系统
How can two parties create a shared symmetric key over an insecure channel? The Diffie-Hellman key exchange protocol solves this without ever transmitting the key itself. Both parties agree on a base g and a prime p, then select private numbers a and b. They exchange gᵃ mod p and gᵇ mod p, then compute (gᵇ mod p)ᵃ and (gᵃ mod p)ᵇ respectively, both yielding the same shared secret gᵃᵇ mod p.
双方如何在不安全信道上建立共享的对称密钥?Diffie-Hellman 密钥交换协议解决了这个问题,而无需传输密钥本身。双方约定基数 g 和素数 p,然后各自选择私有数字 a 和 b。他们交换 gᵃ mod p 和 gᵇ mod p,再分别计算 (gᵇ mod p)ᵃ 和 (gᵃ mod p)ᵇ,两者都得到相同的共享秘密 gᵃᵇ mod p。
Although an eavesdropper can see p, g, gᵃ mod p and gᵇ mod p, they cannot easily compute the shared secret without knowing a or b. This is called the discrete logarithm problem.
虽然窃听者可以看到 p、g、gᵃ mod p 和 gᵇ mod p,但在不知道 a 或 b 的情况下很难计算共享秘密。这被称为离散对数问题。
In modern practice, systems use a hybrid approach: asymmetric encryption (or Diffie-Hellman) to exchange a temporary session key, and symmetric encryption (AES) for the actual message data. This combines the security of asymmetric key distribution with the speed of symmetric encryption.
在现代实践中,系统使用混合方法:非对称加密(或 Diffie-Hellman)用于交换临时会话密钥,对称加密(AES)用于实际消息数据。这结合了非对称密钥分发的安全性和对称加密的高速度。
10. Practical Examples of Encryption in the Real World | 加密在现实世界中的实际应用
HTTPS, the secure version of HTTP, uses exactly this hybrid model. When you visit a website with HTTPS, the server presents a digital certificate containing its public key. Your browser and the server perform a TLS handshake, agreeing on a symmetric session key through asymmetric encryption. Subsequent data flows are encrypted with AES.
HTTPS(HTTP 的安全版本)正是使用这种混合模型。当访问 HTTPS 网站时,服务器出示包含其公钥的数字证书。浏览器和服务器执行 TLS 握手,通过非对称加密协商对称会话密钥。后续数据传输使用 AES 加密。
Other applications include SSH for secure remote login, PGP for email encryption, and secure messaging applications. In every case, asymmetric encryption handles the initial authentication and key exchange, while symmetric encryption handles bulk traffic.
其他应用包括用于安全远程登录的 SSH、用于电子邮件加密的 PGP 以及安全消息应用。在每种情况下,非对称加密处理初始认证和密钥交换,对称加密处理大量流量。
- Wi-Fi WPA2/WPA3 uses AES-CCMP for data privacy.
- Bitcoin addresses are derived from public keys via hash functions.
- Payment cards use RSA or ECC to protect transaction data.
- Wi-Fi WPA2/WPA3 使用 AES-CCMP 保护数据隐私。
- 比特币地址通过哈希函数从公钥派生。
- 支付卡使用 RSA 或 ECC 保护交易数据。
11. Quantum Computing and the Future of Encryption | 量子计算与加密的未来
Quantum computers threaten asymmetric encryption because Shor’s algorithm can factor large numbers in polynomial time. A sufficiently powerful quantum computer could break RSA and ECC. In contrast, symmetric encryption such as AES is less threatened; Grover’s algorithm reduces the effective key strength from 128 bits to 64 bits, which is still feasible with longer keys.
量子计算机威胁非对称加密,因为 Shor 算法可以在多项式时间内分解大数。足够强大的量子计算机可以破解 RSA 和 ECC。相比之下,对称加密如 AES 受到的威胁较小;Grover 算法将有效密钥强度从 128 位降为 64 位,但使用更长的密钥仍然可行。
For this reason, researchers are developing post-quantum cryptography algorithms designed to resist quantum attacks. The field includes lattice-based, code-based, and hash-based schemes. These new algorithms are still asymmetric, but they rely on different mathematical problems.
因此,研究人员正在开发旨在抵抗量子攻击的后量子密码学算法。该领域包括基于格、基于编码和基于哈希的方案。这些新算法仍然是非对称的,但它们依赖于不同的数学问题。
12. Summary and Exam Focus | 总结与考点对照
Symmetric encryption is fast but suffers from the key distribution problem. Asymmetric encryption solves key distribution but is slow. The two are complementary and are combined in hybrid systems to achieve both security and performance.evidence.
对称加密速度快,但存在密钥分发问题。非对称加密解决了密钥分发,但速度慢。两者互补,在混合系统中结合使用,以同时实现安全性和高性能。
In CIE examinations, you should be able to: define plaintext, ciphertext and keys; explain the difference between symmetric and asymmetric encryption; give examples of each; describe the key distribution problem; and explain why hybrid encryption is used in TLS/HTTPS. Practice drawing the flow diagrams for encryption and decryption in both models.
在 CIE 考试中,你应该能够:定义明文、密文和密钥;解释对称加密与非对称加密的区别;各举出实例;描述密钥分发问题;并说明为什么在 TLS/HTTPS 中使用混合加密。练习绘制两种模型中加密和解密的流程示意图。
The most common exam error is confusing the role of the public and private keys. Remember: encrypt with the recipient’s public key for confidentiality; encrypt with the sender’s private key for a digital signature.
最常见的考试错误是混淆公钥和私钥的作用。记住:为了保密,使用接收者的公钥加密;为了数字签名,使用发送者的私钥加密。
Published by TutorHao | Computer Science Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)
屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导Cancel reply