Message Boards Message Boards

GROUPS:

Print PGP key blocks after using GenerateAsymmetricKeyPair[] ?

Posted 6 days ago
211 Views
|
2 Replies
|
0 Total Likes
|

In Mathematica 12.0, how can we print a PGP key block for each of the two keys, after generating the keys using GenerateAsymmetricKeyPair[]? By "block", I mean the usual form in which PGP keys are sent for example by email or posted on the web.

It's straightforward enough to print the key (in this example the public one) in the strict sense, using

GenerateAsymmetricKeyPair[  Method -> <|"Type" -> "RSA", "KeySize" -> 4096|>]

followed by

ToUpperCase @ StringJoin[
  Map[IntegerString[#, 16, 2]&,
    ImportByteArray[pair["PublicKey"]["PublicByteArray"], "Byte"]
  ]
]

That code will print the actual key, which here will have 1k hex chars ~ 0.5kB ~ 4kb as specified.

But how can we print the key block in the standard form, which looks like this for the public key

-----BEGIN PGP PUBLIC KEY BLOCK-----
[optional version info]
[blank line]
[several 64-character lines in base64]
[5-character final line in base64, beginning with "="]
-----END PGP PUBLIC KEY BLOCK-----

and this for the private key

-----BEGIN PGP PRIVATE KEY BLOCK-----
[optional version info]
[blank line]
[several 64-character lines in base64]
[a line in base64 of possibly fewer than 64 characters, ending with "=="]
[5-character final line in base64, beginning with "="]
-----END PGP PUBLIC KEY BLOCK-----

?

I realise each key block will contain more information than the key in the strict sense (and in fact the private key block contains both keys in the strict sense as well as further information), but how can one actually generate key blocks using Mathematica? It seems a little strange that the keys can be generated without a problem, but nobody I've asked seems to know how to generate the key blocks which are the standard forms in which keys are usually sent if for example you want to send someone your public key by email or put it on your website, or in the less common circumstance that you want to share your private key.

Many thanks for any help with this! David

2 Replies

Similar question posted here.

Posted 2 days ago

And here too. But what's the answer? :-) There is a lot of knowledge about PGP around - I'm still hoping this will be a cinch for someone who is highly clued in about keyblock protocols to solve.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract