# 密碼學

### 密碼學（Cryptography）是研究如何保護資訊安全的學問。在區塊鏈世界中，密碼學是一切安全的基石——它保護你的私鑰、驗證你的交易、確保資料不被竄改。

***

## 密碼學與區塊鏈

區塊鏈之所以能夠「不可竄改」、「無需信任」，全靠密碼學的魔法。沒有密碼學，區塊鏈就只是一個普通的資料庫。

{% hint style="info" %}
**比特幣的全名**

比特幣白皮書的標題是《Bitcoin: A Peer-to-Peer Electronic Cash System》，但中本聰在介紹自己時說的是「密碼學貨幣」。密碼學是加密貨幣的靈魂。
{% endhint %}

***

## 區塊鏈中的密碼學應用

| 應用場景  | 使用的密碼學技術            |
| ----- | ------------------- |
| 交易簽名  | 橢圓曲線數位簽名（ECDSA）     |
| 區塊連結  | 雜湊函數（SHA-256）       |
| 錢包地址  | 雜湊 + 編碼             |
| 私鑰安全  | 橢圓曲線密碼學（ECC）        |
| 零知識證明 | ZK-SNARKs、ZK-STARKs |

***

## 主要密碼學技術

### 1. 雜湊函數（Hash Function）

把任意長度的資料轉換成固定長度的「指紋」。特點是：

* 單向：無法從指紋還原原始資料
* 抗碰撞：幾乎不可能找到兩個不同的輸入產生相同的輸出

詳見：[雜湊算法](/gei-kai-fa-zhe-de-zhi-nan/cryptography/hash.md)、[SHA-256](/gei-kai-fa-zhe-de-zhi-nan/cryptography/sha256.md)

### 2. 非對稱加密

使用一對金鑰：公鑰和私鑰。

* **私鑰**：只有自己知道，用來簽名
* **公鑰**：可以公開，用來驗證簽名

詳見：[曲線密碼學（ECC）](/gei-kai-fa-zhe-de-zhi-nan/cryptography/qu-mi-ecc.md)

### 3. 數位簽名

用私鑰對訊息簽名，任何人都可以用公鑰驗證。這證明了「這個訊息確實是私鑰持有者發出的」。

***

## 密碼學的力量

{% hint style="success" %}
**有多安全？**

比特幣使用的 256 位元私鑰，可能的組合數量是 2^256，大約是 10^77。這個數字比可觀測宇宙中的原子數量還多！

用現有的電腦技術，暴力破解一個私鑰需要的時間比宇宙的年齡還長。
{% endhint %}

***

## 延伸閱讀

### 雜湊相關

* [雜湊算法](/gei-kai-fa-zhe-de-zhi-nan/cryptography/hash.md) — 密碼學的基礎工具
* [SHA-256](/gei-kai-fa-zhe-de-zhi-nan/cryptography/sha256.md) — 比特幣使用的雜湊算法
* [SHA-3](/gei-kai-fa-zhe-de-zhi-nan/cryptography/sha3.md) — 新一代雜湊標準

### 加密相關

* [曲線密碼學（ECC）](/gei-kai-fa-zhe-de-zhi-nan/cryptography/qu-mi-ecc.md) — 公私鑰的數學基礎
* [零知識證明](/gei-kai-fa-zhe-de-zhi-nan/cryptography/ling-zhi-ming.md) — 在不透露資訊的情況下證明某事

### 編碼相關

* [Base58](/gei-kai-fa-zhe-de-zhi-nan/cryptography/base58.md) — 比特幣地址的編碼方式
* [Base64](/gei-kai-fa-zhe-de-zhi-nan/cryptography/base64.md) — 常見的資料編碼

***

#### 參考資料

* [Cryptography - Wikipedia](https://en.wikipedia.org/wiki/Cryptography)
* [How Bitcoin Works Under the Hood](https://www.youtube.com/watch?v=Lx9zgZCMqXE)

{% embed url="<https://zhuanlan.zhihu.com/p/36591939>" %}


---

# 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://www.0x1.academy/gei-kai-fa-zhe-de-zhi-nan/cryptography.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.
