我在 Golang 中生成了一个私钥,该私钥应该用于对颁发给 NodeJS 中编码的其他服务的 JSON Web 令牌进行签名。
在令牌进行任何交换之前,NodeJS 服务应存储 Golang 客户端的公钥。
我的问题是,我不知道如何导出rsa。公钥转换为与NodeJS npmjs.com/package/jsonwebtoken 一起使用的格式,并在另一个方向上执行相同的操作;这意味着为 Golang 客户端提供 NodeJS 服务的公钥来验证传入的令牌。
编辑:
有问题的代码 https://github.com/zarkones/XENA 在文件 /xena-apep/main.go 第 16 行和第 36 行下查找。
编辑2:
以下是有问题的代码:
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()
}
largeQ
相关分类