Skip to content

Commit

Permalink
generate json keys example
Browse files Browse the repository at this point in the history
  • Loading branch information
FoamyGuy committed Mar 22, 2024
1 parent 5dcfc26 commit 1f75c32
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions examples/rsa_generate_json_keys.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# SPDX-FileCopyrightText: 2024 Tim Cocks
# SPDX-License-Identifier: MIT
"""
This script can be used to generate a new key pair and output them as JSON.
You can copy the JSON from serial console and paste it into a new file
on the device and then use it with the rsa_json_keys.py example.
"""
import json
import adafruit_rsa


# Create a keypair
print("Generating keypair...")
(public_key, private_key) = adafruit_rsa.newkeys(512)


print("public json:")
print("-------------------------------")
public_obj = {"public_key_arguments": [public_key.n, public_key.e]}
print(json.dumps(public_obj))
print("-------------------------------")


print("private json:")
print("-------------------------------")
private_obj = {
"private_key_arguments": [
private_key.n,
private_key.e,
private_key.d,
private_key.p,
private_key.q,
]
}
print(json.dumps(private_obj))
print("-------------------------------")

0 comments on commit 1f75c32

Please sign in to comment.