Coherence
Search…
RSA
RSA video
RSA sign
In order to understand hex and type parameters read Hash

RSA

spec
Description: Public-key cryptosystem
Problem: Integer Factoriation
Uses: Encrypt, 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 rsa(data_js, bits):
12
req=json.loads(data_js)
13
req["length"]=bits
14
print "Send gen parameters : \n " + json.dumps(req) +"\n"
15
data_js_n=sending(json.dumps(req))
16
answ=json.loads(data_js_n)
17
print "Recived rsa gen: \n"+(json.dumps(answ)) +"\n\n\n"
18
json_s=json_v='{ "version": 1 , "algorithm":"RSA", "type":"string","plaintext": "Hello world!", "hex":0,"privkey": "" ,"operation":"sign"}'
19
req=json.loads(json_s)
20
req["privkey"]=answ["privkey"]
21
print "Send sign : \n " + json.dumps(req) +"\n"
22
data_js_n=sending(json.dumps(req))
23
answ_1=json.loads(data_js_n)
24
print "Recived sign done: \n"+(json.dumps(answ_1)) +"\n\n\n"
25
json_v='{ "version": 1 , "algorithm":"RSA", "type":"string","plaintext": "Hello world!", "hex":0,"pubkey": "" ,"sign":"","operation":"verify"}'
26
req=json.loads(json_v)
27
req["pubkey"]=answ["pubkey"]
28
req["sign"]=answ_1["sign"]
29
print "Send verify : \n " + json.dumps(req) +"\n"
30
data_js_n=sending(json.dumps(req))
31
answ_2=json.loads(data_js_n)
32
print "Recived verify done: \n"+(json.dumps(answ_2)) +"\n\n\n"
33
json_enc='{ "version": 1 , "algorithm":"RSA", "type":"string","pubkey": "" ,"operation":"enc", "plaintext":"Hello world!","hex":0 }'
34
req=json.loads(json_enc)
35
req["pubkey"]=answ["pubkey"]
36
print "Send enc : \n " + json.dumps(req) +"\n"
37
data_js_n=sending(json.dumps(req))
38
answ_3=json.loads(data_js_n)
39
print "Recived enc done: \n"+(json.dumps(answ_3)) +"\n\n\n"
40
json_dec='{ "version": 1 , "algorithm":"RSA", "type":"string","privkey": "" ,"operation":"dec", "plaintext":"" }'
41
req=json.loads(json_dec)
42
req["privkey"]=answ["privkey"]
43
req["plaintext"]=answ_3["result"]
44
print "Send dec : \n " + json.dumps(req) +"\n"
45
data_js_n=sending(json.dumps(req))
46
answ_3=json.loads(data_js_n)
47
print "Recived dec done: \n"+(json.dumps(answ_3)) +"\n\n\n"
48
49
50
51
rsa_gen='{ "version": 1 , "algorithm":"RSA", "operation":"gen" , "length": 0 }'
52
rsa(rsa_gen,1024)
Copied!
In this example we generate a RSA key (1024 bits), sign and validate "Hello world!" string, we enc and dec "Hello world!" string.
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":"RSA", "operation":"gen" , "length": INT }
Copied!
Json to sign
1
{ "version": 1 , "algorithm":"RSA", "type":"string","plaintext": "your string", "hex":BOOL,"privkey": "your hex privkey" ,"operation":"sign"}
Copied!
Json to verify
1
{ "version": 1 , "algorithm":"RSA", "type":"string","plaintext": "your string", "hex":BOOL,"pubkey": "your hex pubkey" ,"sign":"your hex signature","operation":"verify"}
Copied!
Json to enc
1
{ "version": 1 , "algorithm":"RSA", "type":"string","pubkey": "your hex pubkey" ,"operation":"enc", "plaintext":"your string","hex":BOOL }
Copied!
Json to dec
1
{ "version": 1 , "algorithm":"RSA", "type":"string","privkey": "your hex privkey" ,"operation":"dec", "plaintext":"your enc hex string" }
Copied!
Last modified 9mo ago
Copy link