Golang code-google-com-p-go-crypto-ripemd160.New类(方法)实例源码

下面列出了Golang code-google-com-p-go-crypto-ripemd160.New 类(方法)源码代码实例,从而了解它的用法。

作者:liudc    项目:gocoi   
func RimpHash(in []byte, out []byte) {
	sha := sha256.New()
	sha.Write(in)
	rim := ripemd160.New()
	rim.Write(sha.Sum(nil)[:])
	copy(out, rim.Sum(nil))
}

作者:n1rvan    项目:go-hdwalle   
func hash160(data []byte) []byte {
	sha := sha256.New()
	ripe := ripemd160.New()
	sha.Write(data)
	ripe.Write(sha.Sum(nil))
	return ripe.Sum(nil)
}

作者:Zoramit    项目:rippl   
func Sha256RipeMD160(b []byte) []byte {
	ripe := ripemd160.New()
	sha := sha256.New()
	sha.Write(b)
	ripe.Write(sha.Sum(nil))
	return ripe.Sum(nil)
}

作者:msecre    项目:em   
// Convert ECC-256 Public Key to an EMP address (raw 25 bytes).
func GetAddress(log chan string, x, y *big.Int) []byte {
	pubKey := elliptic.Marshal(elliptic.P256(), x, y)
	ripemd := ripemd160.New()

	sum := sha512.Sum384(pubKey)
	sumslice := make([]byte, sha512.Size384, sha512.Size384)
	for i := 0; i < sha512.Size384; i++ {
		sumslice[i] = sum[i]
	}

	ripemd.Write(sumslice)
	appender := ripemd.Sum(nil)
	appender = appender[len(appender)-20:]
	address := make([]byte, 1, 1)

	// Version 0x01
	address[0] = 0x01
	address = append(address, appender...)

	sum = sha512.Sum384(address)
	sum = sha512.Sum384(sum[:])

	for i := 0; i < 4; i++ {
		address = append(address, sum[i])
	}

	return address
}

作者:eris-lt    项目:toadserve   
// General Convenience
func SimpleHashFromBinary(item interface{}) []byte {
	hasher, n, err := ripemd160.New(), new(int64), new(error)
	wire.WriteBinary(item, hasher, n, err)
	if *err != nil {
		PanicCrisis(err)
	}
	return hasher.Sum(nil)
}

作者:nictuk    项目:bit   
// Bitmessage produces a hash for the provided message using a SHA-512 in the
// first round and a RIPEMD-160 in the second.
func Bitmessage(msg []byte) ([]byte, error) {
	s := sha512.New()
	s.Write(msg)

	r := ripemd160.New()
	r.Write(s.Sum(nil))
	return r.Sum(nil), nil
}

作者:jaekwo    项目:GuppyCam   
func BinaryRipemd160(o interface{}) []byte {
	hasher, n, err := ripemd160.New(), new(int64), new(error)
	WriteBinary(o, hasher, n, err)
	if *err != nil {
		panic(*err)
	}
	return hasher.Sum(nil)
}

作者:spartacus    项目:gocoi   
// Returns hash: RIMP160( SHA256( data ) )
func Rimp160AfterSha256(in []byte) (res [20]byte) {
	sha := sha256.New()
	sha.Write(in)
	rim := ripemd160.New()
	rim.Write(sha.Sum(nil)[:])
	copy(res[:], rim.Sum(nil))
	return
}

作者:haowang101    项目:kaij   
func execRipemd160(ctx *execContext, op Opcode, _ []byte) error {
	if ctx.stack.empty() {
		return errStackItemMissing
	}
	r := ripemd160.New()
	r.Write(ctx.stack.pop())
	ctx.stack.push(r.Sum(nil))
	return nil
}

作者:eris-lt    项目:toadserve   
func (part *Part) Hash() []byte {
	if part.hash != nil {
		return part.hash
	} else {
		hasher := ripemd160.New()
		hasher.Write(part.Bytes) // doesn't err
		part.hash = hasher.Sum(nil)
		return part.hash
	}
}

作者:haowang101    项目:kaij   
func execHash160(ctx *execContext, op Opcode, _ []byte) error {
	if ctx.stack.empty() {
		return errStackItemMissing
	}
	h := sha256.Sum256(ctx.stack.pop())
	r := ripemd160.New()
	r.Write(h[:])
	ctx.stack.push(r.Sum(nil))
	return nil
}

作者:robca    项目:rippl   
func Sha256RipeMD160(b []byte) ([]byte, error) {
	ripe := ripemd160.New()
	sha := sha256.New()
	if _, err := sha.Write(b); err != nil {
		return nil, err
	}
	if _, err := ripe.Write(sha.Sum(nil)); err != nil {
		return nil, err
	}
	return ripe.Sum(nil), nil
}

作者:eris-lt    项目:toadserve   
func SimpleHashFromTwoHashes(left []byte, right []byte) []byte {
	var n int64
	var err error
	var hasher = ripemd160.New()
	wire.WriteByteSlice(left, hasher, &n, &err)
	wire.WriteByteSlice(right, hasher, &n, &err)
	if err != nil {
		PanicCrisis(err)
	}
	return hasher.Sum(nil)
}

作者:patrickm    项目:picuge   
func GetHash(a string) (hash.Hash, error) {
	var h hash.Hash
	switch a {
	case "adler32":
		h = adler32.New()
	case "crc32", "crc32ieee":
		h = crc32.New(crc32.MakeTable(crc32.IEEE))
	case "crc32castagnoli":
		h = crc32.New(crc32.MakeTable(crc32.Castagnoli))
	case "crc32koopman":
		h = crc32.New(crc32.MakeTable(crc32.Koopman))
	case "crc64", "crc64iso":
		h = crc64.New(crc64.MakeTable(crc64.ISO))
	case "crc64ecma":
		h = crc64.New(crc64.MakeTable(crc64.ECMA))
	case "fnv", "fnv32":
		h = fnv.New32()
	case "fnv32a":
		h = fnv.New32a()
	case "fnv64":
		h = fnv.New64()
	case "fnv64a":
		h = fnv.New64a()
	case "hmac", "hmacsha256":
		h = hmac.New(sha256.New, []byte(key))
	case "hmacmd5":
		h = hmac.New(md5.New, []byte(key))
	case "hmacsha1":
		h = hmac.New(sha1.New, []byte(key))
	case "hmacsha512":
		h = hmac.New(sha512.New, []byte(key))
	case "md4":
		h = md4.New()
	case "md5":
		h = md5.New()
	case "ripemd160":
		h = ripemd160.New()
	case "sha1":
		h = sha1.New()
	case "sha224":
		h = sha256.New224()
	case "sha256":
		h = sha256.New()
	case "sha384":
		h = sha512.New384()
	case "sha512":
		h = sha512.New()
	default:
		return nil, errors.New("Invalid algorithm")
	}
	return h, nil
}

作者:eris-lt    项目:toadserve   
func (kv KVPair) Hash() []byte {
	hasher, n, err := ripemd160.New(), new(int64), new(error)
	wire.WriteString(kv.Key, hasher, n, err)
	if kvH, ok := kv.Value.(Hashable); ok {
		wire.WriteByteSlice(kvH.Hash(), hasher, n, err)
	} else {
		wire.WriteBinary(kv.Value, hasher, n, err)
	}
	if *err != nil {
		PanicSanity(*err)
	}
	return hasher.Sum(nil)
}

作者:linhua5    项目:gitchai   
func ECDSAPublicKeyToString(key ecdsa.PublicKey) string {
	x := key.X.Bytes()
	y := key.Y.Bytes()
	sha := util.SHA256(append(append([]byte{0x04}, x...), y...)) // should it be 0x04?
	ripe := ripemd160.New().Sum(sha)
	ripesha := util.SHA256(ripe)
	ripedoublesha := util.SHA256(ripesha)
	head := ripedoublesha[0:3]
	final := append(ripe, head...)
	i := new(big.Int)
	i.SetBytes(final)
	var b []byte
	return string(base58.EncodeBig(b, i))
}

作者:philson    项目:go-bitcoin-multisi   
// Hash160 performs the same operations as OP_HASH160 in Bitcoin Script
// It hashes the given data first with SHA256, then RIPEMD160
func Hash160(data []byte) ([]byte, error) {
	//Does identical function to Script OP_HASH160. Hash once with SHA-256, then RIPEMD-160
	if data == nil {
		return nil, errors.New("Empty bytes cannot be hashed")
	}
	shaHash := sha256.New()
	shaHash.Write(data)
	hash := shaHash.Sum(nil) //SHA256 first
	ripemd160Hash := ripemd160.New()
	ripemd160Hash.Write(hash)
	hash = ripemd160Hash.Sum(nil) //RIPEMD160 second

	return hash, nil
}

作者:jaekwo    项目:GuppyCam   
func ripemd160Func(input []byte, gas *uint64) (output []byte, err error) {
	// Deduct gas
	gasRequired := uint64((len(input)+31)/32)*GasRipemd160Word + GasRipemd160Base
	if *gas < gasRequired {
		return nil, ErrInsufficientGas
	} else {
		*gas -= gasRequired
	}
	// Hash
	hasher := ripemd160.New()
	_, err = hasher.Write(input)
	if err != nil {
		panic(err)
	}
	return LeftPadBytes(hasher.Sum(nil), 32), nil
}

作者:eris-lt    项目:toadserve   
// NOTE: sets hashes recursively
func (node *IAVLNode) hashWithCount(t *IAVLTree) ([]byte, int) {
	if node.hash != nil {
		return node.hash, 0
	}

	hasher := ripemd160.New()
	buf := new(bytes.Buffer)
	_, hashCount, err := node.writeHashBytes(t, buf)
	if err != nil {
		PanicCrisis(err)
	}
	// fmt.Printf("Wrote IAVL hash bytes: %X\n", buf.Bytes())
	hasher.Write(buf.Bytes())
	node.hash = hasher.Sum(nil)
	// fmt.Printf("Write IAVL hash: %X\n", node.hash)

	return node.hash, hashCount + 1
}

作者:vsergee    项目:btckeygeni   
// ToAddressUncompressed converts a Bitcoin public key to an uncompressed Bitcoin address string.
func (pub *PublicKey) ToAddressUncompressed() (address string) {
	/* See https://en.bitcoin.it/wiki/Technical_background_of_Bitcoin_addresses */

	/* Convert the public key to bytes */
	pub_bytes := pub.ToBytesUncompressed()

	/* SHA256 Hash */
	sha256_h := sha256.New()
	sha256_h.Reset()
	sha256_h.Write(pub_bytes)
	pub_hash_1 := sha256_h.Sum(nil)

	/* RIPEMD-160 Hash */
	ripemd160_h := ripemd160.New()
	ripemd160_h.Reset()
	ripemd160_h.Write(pub_hash_1)
	pub_hash_2 := ripemd160_h.Sum(nil)

	/* Convert hash bytes to base58 check encoded sequence */
	address = b58checkencode(0x00, pub_hash_2)

	return address
}


问题


面经


文章

微信
公众号

扫码关注公众号