Last active
March 22, 2021 07:29
-
-
Save Higgs1/f6771297534024d3c43095af060c0d6b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cryptography | |
import datetime | |
import pgpy | |
pkalg = pgpy.constants.PubKeyAlgorithm.ECDSA | |
curve = pgpy.constants.EllipticCurveOID.NIST_P384 | |
super_secret_number = 12345 | |
created = 0 # datetime | |
name = 'Fluffy McNopants' | |
comment = None | |
email = None | |
usage = { # SCAEE | |
pgpy.constants.KeyFlags.Sign, | |
pgpy.constants.KeyFlags.Certify, | |
pgpy.constants.KeyFlags.Authentication, | |
pgpy.constants.KeyFlags.EncryptCommunications, | |
pgpy.constants.KeyFlags.EncryptStorage, | |
} | |
pk = cryptography.hazmat.primitives.asymmetric.ec.derive_private_key( | |
super_secret_number, curve.curve(), | |
cryptography.hazmat.backends.default_backend() | |
) | |
key = pgpy.PGPKey() | |
key._key = pgpy.packet.PrivKeyV4() | |
key._key.created = datetime.datetime.utcfromtimestamp(created) | |
key._key.pkalg = pkalg | |
key._key.keymaterial = pgpy.packet.fields.ECDSAPriv() | |
key._key.keymaterial.oid = curve | |
key._key.keymaterial.s = pgpy.packet.types.MPI(pk.private_numbers().private_value) | |
key._key.keymaterial.p = pgpy.packet.fields.ECPoint.from_values( | |
curve.curve().key_size, | |
pgpy.packet.fields.ECPointFormat.Standard, | |
pgpy.packet.types.MPI(pk.public_key().public_numbers().x), | |
pgpy.packet.types.MPI(pk.public_key().public_numbers().y), | |
) | |
key._key.keymaterial._compute_chksum() | |
key._key.update_hlen() | |
key.add_uid( | |
uid = pgpy.PGPUID.new(name, comment, email), | |
hash = pgpy.constants.HashAlgorithm.SHA512, | |
created = created, | |
usage = usage, | |
) | |
print(str(key)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment