블록체인2021. 7. 5. 00:51

이더리움 keystore에 대해서는 아래 한글과 영문자료로 우선 전체를 이해할 필요가 있다.

 

https://julien-maffre.medium.com/what-is-an-ethereum-keystore-file-86c8c5917b97

 

What is an Ethereum keystore file?

The barrier to entry to manage your Ethereum private keys is high, mostly because Ethereum clients hide a big part of the cryptographic…

julien-maffre.medium.com

결국 둘다 같은 내용이다.

 

https://medium.com/hexlant/%EC%9D%B4%EB%8D%94%EB%A6%AC%EC%9B%80-keystore-%ED%8C%8C%EC%9D%BC-utc-%EC%83%9D%EC%84%B1-%EB%B0%8F-%EC%95%94%ED%98%B8%ED%99%94-%EB%B3%B5%ED%98%B8%ED%99%94-%EC%9B%90%EB%A6%AC-1-2-d417cb605bf

 

이더리움 KeyStore 파일(UTC) 생성 및 암호화/복호화 원리 (1/2)

이더리움 플랫폼에서는 본인을 확인하는 수단으로 KeyStore 파일을 사용합니다. 사용자는 KeyStore 파일을 생성할 때 입력했던 비밀번호를 통해 유효한 사용자임을 인증하고 계좌에 접근할 수 있게

medium.com

 

 

그러면 이 둘에 해당하는 key들을 직접 생성할 수 없을까?

linux에서 openssl정도로 가능한데, 아래 자세히 설명되어 있다.

 

https://kobl.one/blog/create-full-ethereum-keypair-and-address/

 

Create full Ethereum wallet, keypair and address

Create full Ethereum wallet, keypair and address Generating a usable Ethereum wallet and its corresponding keys Contents This article is a guide on how to generate an ECDSA private key and derive its Ethereum address. Using OpenSSL and keccak-256sum from a

kobl.one

key생성하는 전체 코드(Complete example, linux가정)

# Generate the private and public keys

# openssl을 통해 타원곡선 사용해 개인키/공개키를 생성한다

> openssl ecparam -name secp256k1 -genkey -noout | openssl ec -text -noout > Key

 

# Extract the public key and remove the EC prefix 0x04

# Key에서 공개키를 추출하고 prefix를 제거한다

> cat Key | grep pub -A 5 | tail -n +2 | tr -d '\n[:space:]:' | sed 's/^04//' > pub

 

# Extract the private key and remove the leading zero byte

# Key에서 개인키를 추출하고 앞의 00 byte를 없앤다

> cat Key | grep priv -A 3 | tail -n +2 | tr -d '\n[:space:]:' | sed 's/^00//' > priv

 

# Generate the hash and take the address part

# 해쉬값을 생성해서 주소를 만들어 낸다

# linux에서는 $ git clone https://github.com/vkobel/ethereum-generate-wallet 한 후에 ethereum-generate-wallet/lib/x86-64/keccak-256sum을 활용한다

 

> cat pub | keccak-256sum -x -ltr -d ' -' | tail -c 41 > address

  *0xdcc703c0E500B653Ca82273B7BFAd8045D85a470 처럼 생긴 주소는 비어있는 공개키로 생성된 것이라 주의해야 한다.

  재미있게도 이렇게 잘못 생성한 주소로 돈을 보낸 사람이 적지 않다. 여기서 볼 수 있다. etherscan

   ex> $ touch empty; cat empty | keccak-256sum -x -l | tr -d ' -' | tail -c 41

 

# (Optional) import the private key to geth

# geth로 개인키를 가지고 실제 맞는지 검증해볼 수 있다

 

> geth account import priv

 

ex> $ ./geth --datadir "/Users/neibc/dev/geth/data2" --networkid 2125 account import prv  #prv파일에 위 prv 저장 가정

        출력되는 geth의 address가 상기의 생성한 address와 맞는지 확인한다.

 

 

 

마지막으로 또 재미있는 것은 0x7e5f4552091a69125d5dfcb7b8c2659029395bdf 라는 주소이다. 이 지갑주소는 private key가 알려져있다. 아래를 참조해보자. ( https://lsongnotes.wordpress.com/2018/04/30/manually-decrypting-ethereum-keystore-file/ )

 

Ex>

$ echo "0000000000000000000000000000000000000000000000000000000000000001" > plain_key1.txt
$ geth –datadir . account import plain_key1.txt

 

etc...

$ echo "3141592653589793238462643383279502884197169399375105820974944592" > plain_key2.txt
$ geth –datadir . account import plain_key2.txt

$ echo "2718281828459045235360287471352662497757247093699959574966967627" > plain_key3.txt
$ geth –datadir . account import plain_key3.txt

 

이렇게 하면 위 주소가 나온다. 신기하게도 누군가 이 계좌로 소액을 입금하고 있으며, 입금 즉시 곧바로 출금한다.

https://www.blockchain.com/eth/address/0x7e5f4552091a69125d5dfcb7b8c2659029395bdf

 

 

반응형
Posted by 작동미학