Skip to content

Commit 999b41b

Browse files
authored
Merge pull request #42 from FoamyGuy/gen_json_keys
generate json keys example
2 parents 5dcfc26 + 1f75c32 commit 999b41b

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

examples/rsa_generate_json_keys.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# SPDX-FileCopyrightText: 2024 Tim Cocks
2+
# SPDX-License-Identifier: MIT
3+
"""
4+
This script can be used to generate a new key pair and output them as JSON.
5+
You can copy the JSON from serial console and paste it into a new file
6+
on the device and then use it with the rsa_json_keys.py example.
7+
"""
8+
import json
9+
import adafruit_rsa
10+
11+
12+
# Create a keypair
13+
print("Generating keypair...")
14+
(public_key, private_key) = adafruit_rsa.newkeys(512)
15+
16+
17+
print("public json:")
18+
print("-------------------------------")
19+
public_obj = {"public_key_arguments": [public_key.n, public_key.e]}
20+
print(json.dumps(public_obj))
21+
print("-------------------------------")
22+
23+
24+
print("private json:")
25+
print("-------------------------------")
26+
private_obj = {
27+
"private_key_arguments": [
28+
private_key.n,
29+
private_key.e,
30+
private_key.d,
31+
private_key.p,
32+
private_key.q,
33+
]
34+
}
35+
print(json.dumps(private_obj))
36+
print("-------------------------------")

0 commit comments

Comments
 (0)