master
兔子 3 years ago
parent 32955497cb
commit b315397ac6

@ -947,11 +947,11 @@ func RSADecrypt(data, private []byte, password string) ([]byte, error) {
} }
// RSASign RSA私钥签名加密 // RSASign RSA私钥签名加密
func RSASign(hashdata, private []byte, password string, hashtype crypto.Hash) ([]byte, error) { func RSASign(msg, priKey []byte, password string, hashType crypto.Hash) ([]byte, error) {
var prikey *rsa.PrivateKey var prikey *rsa.PrivateKey
var err error var err error
var bytes []byte var bytes []byte
blk, _ := pem.Decode(private) blk, _ := pem.Decode(priKey)
if blk == nil { if blk == nil {
return []byte{}, errors.New("private key error") return []byte{}, errors.New("private key error")
} }
@ -972,12 +972,17 @@ func RSASign(hashdata, private []byte, password string, hashtype crypto.Hash) ([
} }
prikey = tmp.(*rsa.PrivateKey) prikey = tmp.(*rsa.PrivateKey)
} }
return rsa.SignPKCS1v15(rand.Reader, prikey, hashtype, hashdata) hashMethod := hashType.New()
_, err = hashMethod.Write(msg)
if err != nil {
return nil, err
}
return rsa.SignPKCS1v15(rand.Reader, prikey, hashType, hashMethod.Sum(nil))
} }
// RSAVerify RSA公钥签名验证 // RSAVerify RSA公钥签名验证
func RSAVerify(data, hashdata, public []byte, hashtype crypto.Hash) error { func RSAVerify(data, msg, pubKey []byte, hashType crypto.Hash) error {
blk, _ := pem.Decode(public) blk, _ := pem.Decode(pubKey)
if blk == nil { if blk == nil {
return errors.New("public key error") return errors.New("public key error")
} }
@ -985,7 +990,12 @@ func RSAVerify(data, hashdata, public []byte, hashtype crypto.Hash) error {
if err != nil { if err != nil {
return err return err
} }
return rsa.VerifyPKCS1v15(pubkey.(*rsa.PublicKey), hashtype, hashdata, data) hashMethod := hashType.New()
_, err = hashMethod.Write(msg)
if err != nil {
return err
}
return rsa.VerifyPKCS1v15(pubkey.(*rsa.PublicKey), hashType, hashMethod.Sum(nil), data)
} }
// VicqueEncodeV1 Best // VicqueEncodeV1 Best

Loading…
Cancel
Save