Search Docs
openssl genrsa -out publicKey.pem 2048 openssl rsa -in privateKey.pem -pubout -out publicKey.pem
NodeJS 签名验签写入sign , Golang读取Sign验签 ps: pkcs8 密钥须转换
// rsa_test.js const crypto = require('crypto') const fs = require('fs') const publicKey = fs.readFileSync("publicKey.pem") const privateKey = fs.readFileSync("privateKey.pem") const dataStr = "verifiableData" const signer = crypto.createSign('sha256') signer.update(dataStr) const sign = signer.sign(privateKey,'base64') const verifier = crypto.createVerify('sha256') verifier.update(dataStr); const ver = verifier.verify(publicKey, sign,'base64'); console.log(sign,ver); fs.writeFileSync("sign.txt",sign)
oCvBK9YEJe58gkB1jzoTPOH4ToEa...==
true
// rsa_test.go package main import ( "crypto" "log" "os" "testing" ) func TestRsa2Rsa2PriSign(t *testing.T) { PUBLIC_KEY, _ := os.ReadFile("./publicKey.pem") signTxt, _ := os.ReadFile("./sign.txt") signStr := string(signTxt) publicKey := string(PUBLIC_KEY) str := "verifiableData" res := RSAPubCheckSign(str, signStr, publicKey, crypto.SHA256) fmt.Println(signStr) fmt.Println(res) }