neoneo-go/pkg/crypto/publickey/TestHelper/helper.go
2019-02-25 22:44:14 +00:00

20 lines
475 B
Go
Executable file

package pubkeytesthelper
import (
"github.com/CityOfZion/neo-go/pkg/crypto/hash"
"github.com/CityOfZion/neo-go/pkg/crypto/privatekey"
)
func SignDataWithRandomPrivateKey(data []byte) (bool, error) {
hashedData, _ := hash.Sha256(data)
privKey, _ := privatekey.NewPrivateKey()
signedData, err := privKey.Sign(data)
pubKey, _ := privKey.PublicKey()
result := pubKey.Verify(signedData, hashedData.Bytes())
if err != nil {
return false, err
}
return result, nil
}