$pkeyid = openssl_pkey_get_private ( $priv_key );
openssl_sign ( $params_str, $signMsg, $pkeyid, OPENSSL_ALGO_SHA1 );
openssl_free_key ( $pkeyid );
$signMsg = base64_encode ( $signMsg );
I would like to ask how to use GO to implement signatures like PHP. The code I wrote is as follows, which is always unsuccessful
.func getSing(splice string, priKey []byte) (encrypt string) {
PEMBlock, _ := pem.Decode(priKey)
if PEMBlock == nil {
log.Fatal("PEM")
}
privkey, err := x509.ParsePKCS8PrivateKey(PEMBlock.Bytes)
if err != nil {
log.Fatal(err)
}
pri, ok := privkey.(*rsa.PrivateKey)
if ok {
// SH256 := crypto.SHA256
// hashed := sha256.Sum256([]byte(fmt.Sprintf("%x", sha256.Sum256([]byte(splice)))))
// hashed := sha256.Sum256([]byte(nil))
// sign, err := rsa.SignPKCS1v15(rand.Reader, pri, SH256, hashed[:])
SH1 := crypto.SHA1
// hashed := sha1.Sum([]byte(fmt.Sprintf("%x", sha1.Sum([]byte(splice)))))
hashed := sha1.Sum([]byte(nil))
sign, err := rsa.SignPKCS1v15(rand.Reader, pri, SH1, hashed[:])
if err != nil {
log.Fatal(err)
}
return Base64Encode(sign)
} else {
log.Fatal(ok)
}
return
}
ask everyone to help solve it. I"m sure there"s something wrong, which leads to the wrong signature, and the verification of the signature is not correct
.