Coherence
Search…
ECC

ECC

ECC video
In order to understand hex and type parameters read HASH

ECIES

spec
Description: Public-key cryptosystem
Problem: Discrete logarithm problem
Uses: Encrypt
    It only supports "type":"string"

ECDSA

spec
Description: Public-key cryptosystem
Problem: Discrete logarithm problem
Uses: Digital signatures
    It only supports "type":"string"

How to ???

1
import requests
2
import json
3
import os,binascii
4
5
def sending(message):
6
url = 'http://127.0.0.1:6613/'
7
response = requests.post(url, data=message)
8
print response.content
9
return response.content
10
11
def ecc_pb(data_js):
12
req=json.loads(data_js)
13
curve=req["curve"]
14
print "Send gen parameters : \n" + data_js +"\n"
15
data_js_n=sending(json.dumps(req))
16
answ=json.loads(data_js_n)
17
print 'Recived ecc gen: \n'+ json.dumps(answ) +"\n\n\n"
18
json_enc='{ "version": 1 , "algorithm":"ECIES", "type":"string","pubkey": "" ,"operation":"enc", "plaintext":"Hello world!" ,"curve":""}'
19
req=json.loads(json_enc)
20
req["pubkey"]=answ["pubkey"]
21
req["curve"]=curve
22
print "Send enc: \n"+(json.dumps(req))+"\n"
23
data_js_n=sending(json.dumps(req))
24
answ_1=json.loads(data_js_n)
25
print "Recived enc : \n"+(json.dumps(answ_1)) +"\n"
26
req["privkey"]=answ["privkey"]
27
req["plaintext"]=answ_1["result"]
28
req["pubkey"]=""
29
req["operation"]="dec"
30
data_js_n=sending(json.dumps(req))
31
answ_2=json.loads(data_js_n)
32
print "Recived dec done: \n"+(json.dumps(answ_2)) +"\n\n\n"
33
json_sign='{ "version": 1 , "algorithm":"ECDSA", "type":"string","plaintext": "Hello world", "hex":0,"privkey": "" ,"operation":"sign"}'
34
req=json.loads(json_sign)
35
req["privkey"]=answ["privkey"]
36
req["curve"]=curve
37
data_js_n=sending(json.dumps(req))
38
answ_3=json.loads(data_js_n)
39
print "Recived sign done: \n"+(json.dumps(answ_3)) +"\n"
40
json_verify='{ "version": 1 , "algorithm":"ECDSA", "type":"string","plaintext": "Hello world", "hex":0,"pubkey": "", "operation":"verify","sign":""}'
41
req=json.loads(json_verify)
42
req["pubkey"]=answ["pubkey"]
43
req["sign"]=answ_3["sign"]
44
req["curve"]=curve
45
data_js_n=sending(json.dumps(req))
46
answ_4=json.loads(data_js_n)
47
print "Recived verify done: \n"+(json.dumps(answ_4)) +"\n\n\n"
48
49
50
ecc_gen='{ "version": 1 , "algorithm":"ECC_GEN", "curve":"secp256k1"}'
51
ecc_pb(ecc_gen)
Copied!
In this example we generate a ECC key (secp256k1), sign and validate "Hello world!" string, we enc and dec "Hello world!" string.
On "curve" can be one of {"brainpoolP512r1","secp521r1","brainpoolP384r1","secp384r1","brainpoolP320r1","brainpoolP256r1", "secp256k1","sect571r1","sect571k1","sect409r1","sect409k1","sect283r1","sect283k1"}
The default hash function to sign is sha3256, you can change by adding "hashsign" and can be one of {"sha3_512","sha3_384","sha3_256","sha3_224","sha_512","sha_384","sha_256","sha_224","sha_1","whirlpool"}
Json to gen
1
{ "version": 1 , "algorithm":"ECC_GEN", "curve":"curve flavor"}
Copied!
Json to enc
1
{ "version": 1 , "algorithm":"ECIES", "type":"string", "hex":BOOL,"pubkey": "your hex pubkey",
2
"operation":"enc", "plaintext":"your string" ,"curve":"curve flavor"}
Copied!
Json to dec
1
{ "version": 1 , "algorithm":"ECIES", "type":"string","privkey": "your hex privkey" ,
2
"operation":"dec", "plaintext":"your hex enc string" ,"curve":"curve flavor"}
Copied!
Json to sign
1
{ "version": 1 , "algorithm":"ECDSA", "type":"string","plaintext": "your string", "hex":BOOL,
2
"privkey": " your hex pirvkey" ,"operation":"sign","curve":"curve flavor"}
Copied!
Json to verify
1
{ "version": 1 , "algorithm":"ECDSA", "type":"string","plaintext": "your string", "hex":BOOL,
2
"pubkey": "your hex pubkey" ,"sign":"your hex signature","operation":"verify","curve":"curve flavor"}
Copied!
Copy link