This sample demonstrates how to create a valid Metadata Registry envelope, containing a JWT token encoded with an RSA key pair.
To generate a valid RSA key pair, we recommend using Git Bash for Windows.
Once you have that installed, start a Git Bash session and run:
ssh-keygen -t rsa -b 4096 -f metadataregistry.key
ssh-keygen -f metadataregistry.key.pub -e -m pem > metadataregistry.key.pem
This will generate all your necessary key files.
Encoding the JSON payload isn't trivial in .NET due to poor framework support for dealing with RSA key pairs. Fortunately, the BouncyCastle suite fills in the blanks. JWT support is given by Jose.
RsaPrivateCrtKeyParameters privateKey;
using (var reader = File.OpenText(secretKeyPath))
{
privateKey = (RsaPrivateCrtKeyParameters)((AsymmetricCipherKeyPair)new PemReader(reader).ReadObject()).Private;
}
string publicKey = File.ReadAllText(publicKeyPath);
string encoded = JWT.Encode(contents, DotNetUtilities.ToRSA(privateKey), JwsAlgorithm.RS256);
A full sample is available at Envelope.cs.
MetadataRegistryExample.exe [path_to_public_key] [path_to_private_key] [path_to_payload]
The resulting envelope is printed to standard output.