#!/usr/bin/env python3 from ob_save import get_fingerprint_by_email, write_gpg_file, read_gpg_file import json """ First we open the normal json data and loads it as a dict, this is our dummy data. "raw_json" """ with open("json_stuff.txt", "r") as json_file: raw_json = json.load(json_file) """ Lets show the raw json, and verify that it is a dictionary""" print("#"*30, "\n") print("raw_json content:", raw_json) print("raw_json type: ", type(raw_json)) print("\n", "#"*30, "\n") """ Setup constants """ signature_email = "b1-systems@example.com" gpg_fingerprint = get_fingerprint_by_email(signature_email) """ Lets sign and write the content to a new file""" print("Writing json to file.") write_gpg_file(raw_json, "target_filename.txt", fingerprint=gpg_fingerprint) """ Lets read back the content, AND verify that the signature is valid """ gpg_content = read_gpg_file("more_json_stuff.txt"+".gpg", verify=True) """ gpg_content is a dictonary with more than just the json, so lets split it in its nessecary parts.""" readback_json = json.loads(gpg_content["json"]) verified_status = gpg_content["verified"] print("\n", "#"*30, "\n") print("Is original json and readback json identical?: {}".format(readback_json == raw_json)) print("Is signature valid?: {}".format(verified_status))