Example #1
0
func SignatureVerify(publicKey, sig, hash []byte) bool {

	b, _ := base58.DecodeToBig(publicKey)
	publ := splitBig(b, 2)
	x, y := publ[0], publ[1]

	b, _ = base58.DecodeToBig(sig)
	sigg := splitBig(b, 2)
	r, s := sigg[0], sigg[1]

	pub := ecdsa.PublicKey{elliptic.P224(), x, y}

	return ecdsa.Verify(&pub, hash, r, s)
}
Example #2
0
// NewNodeIDFromString generates NodeID from the given base58-encoded string.
func NewNodeIDFromString(str string) (NodeID, error) {
	i, err := base58.DecodeToBig([]byte(str))
	if err != nil {
		return NodeID{}, err
	}
	return NewNodeIDFromBytes(i.Bytes())
}
func checkSignature(signature string, request string, token string) bool {
	mac := hmac.New(sha256.New, []byte(token))
	mac.Write([]byte(request))
	expectedMAC := mac.Sum(nil)
	decoded_sig, _ := base58.DecodeToBig([]byte(signature))
	messageMAC := decoded_sig.Bytes()

	return hmac.Equal(messageMAC, expectedMAC)
}
Example #4
0
func (k *Keypair) Sign(hash []byte) ([]byte, error) {

	d, err := base58.DecodeToBig(k.Private)
	if err != nil {
		return nil, err
	}

	b, _ := base58.DecodeToBig(k.Public)

	pub := splitBig(b, 2)
	x, y := pub[0], pub[1]

	key := ecdsa.PrivateKey{ecdsa.PublicKey{elliptic.P224(), x, y}, d}

	r, s, _ := ecdsa.Sign(rand.Reader, &key, hash)

	return base58.EncodeBig([]byte{}, bigJoin(KEY_SIZE, r, s)), nil
}
Example #5
0
func BenchmarkBase58DecodeStringSmall(b *testing.B) {
	data := make([]byte, 8)
	data[0] = 0xff // without this, it's just an inefficient zero
	data = []byte(basen.Base58.EncodeToString(data))
	b.SetBytes(int64(len(data)))
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		base58.DecodeToBig(data)
	}
}
Example #6
0
File: key.go Project: h2so5/murcott
// PrivateKeyFromString generates PrivateKey from the given base58-encoded string.
func PrivateKeyFromString(str string) *PrivateKey {
	b, err := base58.DecodeToBig([]byte(str))
	if err != nil {
		return nil
	}
	var out PrivateKey
	err = msgpack.Unmarshal(b.Bytes(), &out)
	if err != nil {
		return nil
	}
	if !out.verifyKey() {
		return nil
	}
	return &out
}
Example #7
0
func main() {
	log.SetFlags(0)
	log.SetPrefix(prog + ": ")

	flag.Usage = usage
	flag.Parse()

	if flag.NArg() < 1 {
		usage()
		os.Exit(1)
	}

	for _, enc := range flag.Args() {
		buf := []byte(enc)
		dec, err := base58.DecodeToBig(buf)
		if err != nil {
			log.Fatal(err)
		}
		_, err = fmt.Println(dec)
		if err != nil {
			log.Fatal(err)
		}
	}
}