64 lines
2.1 KiB
Python
64 lines
2.1 KiB
Python
"""
|
|
python-ecdsa" Copyright (c) 2010 Brian Warner
|
|
|
|
Portions written in 2005 by Peter Pearson and placed in the public domain.
|
|
|
|
Permission is hereby granted, free of charge, to any person
|
|
obtaining a copy of this software and associated documentation
|
|
files (the "Software"), to deal in the Software without
|
|
restriction, including without limitation the rights to use,
|
|
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
copies of the Software, and to permit persons to whom the
|
|
Software is furnished to do so, subject to the following
|
|
conditions:
|
|
|
|
The above copyright notice and this permission notice shall be
|
|
included in all copies or substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
OTHER DEALINGS IN THE SOFTWARE.
|
|
"""
|
|
import json
|
|
from ecdsa import SigningKey, VerifyingKey, SECP256k1
|
|
from ecdsa.util import PRNG
|
|
from base64 import b16decode
|
|
|
|
f = open('temp.json', 'r')
|
|
request = json.load(f)
|
|
f.close()
|
|
|
|
def p2h(data, keymode):
|
|
if(keymode=="sk"):
|
|
sk = SigningKey.from_pem(data.encode())
|
|
print(sk.to_string().hex())
|
|
elif(keymode=="vk"):
|
|
vk = VerifyingKey.from_pem(data.encode())
|
|
print(vk.to_string().hex())
|
|
|
|
def h2p(data, keymode):
|
|
if(keymode=="sk"):
|
|
sk = SigningKey.from_string(b16decode(data.upper().encode()), curve=SECP256k1)
|
|
print(sk.to_pem().decode())
|
|
elif(keymode=="vk"):
|
|
vk = VerifyingKey.from_string(b16decode(data.upper().encode()), curve=SECP256k1)
|
|
print(vk.to_pem().decode())
|
|
|
|
def seed2hkey(data, keymode):
|
|
seed = PRNG(data.encode())
|
|
sk = SigningKey.generate(entropy=seed, curve=SECP256k1)
|
|
print(sk.to_string().hex())
|
|
|
|
switch = {
|
|
"p2h":p2h,
|
|
"h2p":h2p,
|
|
"seed2hkey":seed2hkey
|
|
}
|
|
|
|
switch[request["mode"]](request["data"], request["keymode"])
|