I've generated a private key in Golang, which should be used to sign JSON Web Tokens issued to the other service coded in NodeJS.
Prior to any exchange of the tokens, NodeJS service should store the public key of the Golang client.
My problem is, I don't know how to export a rsa.PublicKey into a format which is working with NodeJS' npmjs.com/package/jsonwebtoken and do the same in the other direction; meaning providing the Golang client with a public key of the NodeJS service to verify incoming tokens.
Edit:
Code in question https://github.com/zarkones/XENA Look under the file /xena-apep/main.go lines 16 and 36.
Edit2:
Here is the code in question:
var privateIdentificationKey = generatePrivateKey() // Generating the private key.
identify(id.String(), privateIdentificationKey.publicKey) // Won't work because of the type miss-match.
/* Generates a private key. */
func generatePrivateKey() *rsa.PrivateKey {
secret, err := rsa.GenerateKey(rand.Reader, 4096)
if err != nil {
fmt.Println(err)
}
return secret
}
/* Makes Xena-Atila aware of its existence. */
func identify(id string, identificationKey string) {
insertionPayload := []byte(`{"id":"` + id + `","identificationKey":"` + identificationKey + `","status":"ALIVE"}`)
request, err := http.NewRequest("POST", centralizedHost+"/v1/clients", bytes.NewBuffer(insertionPayload))
request.Header.Set("Content-Type", "application/json")
if err != nil {
fmt.Println("Unable to connect to the centralized host.")
}
client := &http.Client{}
response, err := client.Do(request)
defer response.Body.Close()
}