# 以太坊的私钥和公钥

### 私钥

#### 通过随机数生成私钥

``````privatekey = SHA256/Keccak-256("很大的随机字符串")
``````

``````f8f8a2f43c8376ccb0871305060d7b27b0554d2cc72bccf41b2705608452f315
``````

### 公钥

#### 椭圆曲线密码学的基本概念

sec.png

mod p（素数的模）表示曲线位于素数阶p的有限域中，这也可以表示为Fp，其中的p=2256–232–29–28–27–26–24–1是一个非常大的素数。

``````Q =
(49790390825249384486033144355916864607616083520101638681403973749255924539515,59574132161899900045862086493921015780032175291755807399284007721050341297360)
``````

``````Python 3.4.0 (default, Mar 30 2014, 19:23:13)
[GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.38)] on darwin
>>> p = 115792089237316195423570985008687907853269984665640564039457584007908834 \
671663
>>> x = 49790390825249384486033144355916864607616083520101638681403973749255924539515
>>> y = 59574132161899900045862086493921015780032175291755807399284007721050341297360
>>> (x ** 3 + 7 - y**2) % p
0L
``````

#### 生成公钥

``````K=k*G
``````

``````K = f8f8a2f43c8376ccb0871305060d7b27b0554d2cc72bccf41b2705608452f315 * G
``````

``````K=(x,y)
``````

``````x = 6e145ccef1033dea239875dd00dfb4fee6e3348b84985c92f103444683bae07b
y = 83b5c38e5e2b0c8529d7fa3f64d46daa1ece2d9ac14cab9477d042c84c32ccd0
``````

0x00 无穷远点 1
0x04 未压缩点 65
0x01 偶数y压缩的点 33
0x03 奇数y压缩的点 33

``````04 + x-coordinate (32 bytes/64 hex) + y-coordinate (32 bytes/64 hex)
``````

``````046e145ccef1033dea239875dd00dfb4fee6e3348b84985c92f103444683bae07b83b5c38e5e2b0 \
c8529d7fa3f64d46daa1ece2d9ac14cab9477d042c84c32ccd0
``````