# 加密和解密

當某個信息被傳送到其他電腦時,第三方很容易被黑客入侵,例如破譯或篡改內容等。

因此,要想加密信息,必須分別有加密、解密(解密)的算法。 但是,僅憑該算法無法解決,因此即使眼前有顯而易見的算法,也要有無法解開加密信息的手段,即鑰匙。 加密算法普遍採用基於密鑰的加密，加密密鑰長度從1位到幾百位不等。

即使黑客獲得了加密的信息並獲得了算法，也必須有一個密鑰來破譯該信息。 如果加密密鑰的長度是 128 位， 那麼 2^128 個加密密鑰中的一個應該是對的 。 即使用一個密碼鑰匙需要1/10,000,000秒的幾百億超級計算機工作，也需要10,790,283,070,806,014,188年。

<br>

## 非對稱和對稱金鑰

加密金鑰主要分為<mark style="color:orange;">非對稱金鑰</mark>和<mark style="color:orange;">對稱金鑰</mark>。 <mark style="color:orange;">非對稱金鑰</mark>是一對金鑰，因此使用一個金鑰進行的加密在沒有另一個金鑰的情況下無法解密。 <mark style="color:orange;">對稱金鑰</mark>要求用於加密的金鑰和用於解密的金鑰相同。 利用這些特性，電腦網路通常使用<mark style="color:orange;">對稱</mark>和<mark style="color:orange;">非對稱金鑰</mark>的組合來傳輸加密訊息。

例如，

主機A想向主機B傳達安全加密的信息。 A製作一對<mark style="color:orange;">非對稱金鑰</mark>，一個自己拿着，另一個傳送給B。 A本人擁有的鑰匙稱爲<mark style="color:orange;">私鑰(Private Key)</mark>，發送給B的鑰匙稱爲<mark style="color:orange;">公鑰(Public Key)</mark>。

<figure><img src="/files/Dz3767bw27uGuh7GTRYM" alt=""><figcaption></figcaption></figure>

B用自己的<mark style="color:orange;">對稱金鑰</mark>加密從A收到的<mark style="color:orange;">公鑰</mark>併發送給A。 A用私鑰解密收到的<mark style="color:orange;">對稱金鑰</mark> ，並共享B創建的<mark style="color:orange;">對稱金鑰</mark>。 在此過程中，即使黑客獲得了<mark style="color:orange;">公鑰</mark>和加密的<mark style="color:orange;">對稱金鑰</mark>，也沒有私鑰，無法知道<mark style="color:orange;">對稱金鑰</mark>的內容。

<figure><img src="/files/c5AezQQC5vyJVxhZDlZP" alt=""><figcaption></figcaption></figure>

現在，A將消息內容用從B收到的<mark style="color:orange;">對稱金鑰</mark>加密後重新發送給B。 B可以通過用<mark style="color:orange;">對稱金鑰</mark>解密加密信件來檢查內容。 即使在這個過程中，由於黑客沒有<mark style="color:orange;">對稱金鑰</mark>，消息也無法解析。

如果黑客破壞信息內容併發送給B，B就無法解密。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.proudnet.com/proudnet.cn/proudnet-note/notes/encryption_decoding.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
