• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang sha512.New384函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中crypto/sha512.New384函数的典型用法代码示例。如果您正苦于以下问题:Golang New384函数的具体用法?Golang New384怎么用?Golang New384使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了New384函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: Sign

// Sign is used to certify a message with the key pair passed in. It returns a
// boolean indicating success; on success, the signature value returned will
// contain the signature.
func Sign(message []byte, key PrivateKey, pub PublicKey) (signature []byte, ok bool) {
	if message == nil {
		return nil, false
	} else if !KeyIsSuitable(key, pub) {
		return nil, false
	}
	h := sha512.New384()
	h.Write(message)
	hash := h.Sum(nil)

	skey, ok := ecdsa_private(key, pub)
	if !ok {
		return
	}
	r, s, err := ecdsa.Sign(PRNG, skey, hash)
	if err != nil {
		ok = false
	} else {
		signature = marshalSignature(r, s)
		if signature == nil {
			ok = false
		}
	}
	return
}
开发者ID:postfix,项目名称:gocryptobox,代码行数:28,代码来源:stoutbox.go


示例2: EndBackup

func (b *BackupSet) EndBackup() error {
	if b.records == nil {
		return fmt.Errorf("Cannot end unstarted backup run")
	}
	start, ok := b.records[b.lastStartIndex].(startRecord)
	if !ok {
		return fmt.Errorf("Corrupted backup set: purported last start record is not a start record")
	}
	start.length = 0
	digester := sha512.New384()
	for i := b.lastStartIndex; i < len(b.records); i++ {
		start.length += b.records[i].Len()
		recordType, data := b.records[i].Record()
		err := binary.Write(digester, binary.BigEndian, uint8(0))
		if err != nil {
			return err
		}
		err = binary.Write(digester, binary.BigEndian, recordType)
		if err != nil {
			return err
		}
		digester.Write(data)
	}
	end := endRecord{digester.Sum(nil)}
	start.length += end.Len()
	b.records[b.lastStartIndex] = start
	b.records = append(b.records, end)
	return nil
}
开发者ID:eadmund,项目名称:cypherback,代码行数:29,代码来源:backup_set.go


示例3: process_file

func process_file(filename string, complete chan Sumlist) {
	sumlist := Sumlist{}
	sumlist.filename = filename

	// Open the file and bail if we fail
	infile, err := os.Open(filename)
	if err != nil {
		log.Printf("Unable to open %s: %s", filename, err)
		complete <- sumlist
		return
	}
	defer infile.Close()

	// Create the checksum objects
	if flag_crc32 {
		sumlist.sums = append(sumlist.sums, Checksum{"CRC32", crc32.New(crc32.IEEETable)})
	}
	if flag_crc64 {
		sumlist.sums = append(sumlist.sums, Checksum{"CRC64", crc64.New(crc64.MakeTable(crc64.ISO))})
	}
	if flag_sha224 {
		sumlist.sums = append(sumlist.sums, Checksum{"SHA224", sha256.New224()})
	}
	if flag_sha256 {
		sumlist.sums = append(sumlist.sums, Checksum{"SHA256", sha256.New()})
	}
	if flag_sha384 {
		sumlist.sums = append(sumlist.sums, Checksum{"SHA384", sha512.New384()})
	}
	if flag_sha512 {
		sumlist.sums = append(sumlist.sums, Checksum{"SHA512", sha512.New()})
	}

	// Create our file reader
	reader := bufio.NewReader(infile)

	// Start a buffer and loop to read the entire file
	buf := make([]byte, 4096)
	for {
		read_count, err := reader.Read(buf)
		// If we get an error that is not EOF, then we have a problem
		if err != nil && err != io.EOF {
			log.Printf("Unable to open %s: %s", filename, err)
			complete <- sumlist
			return
		}
		// If the returned size is zero, we're at the end of the file
		if read_count == 0 {
			break
		}

		// Add the buffer contents to the checksum calculation
		for _, sum := range sumlist.sums {
			sum.hashFunc.Write(buf[:read_count])
		}

	}

	complete <- sumlist
}
开发者ID:joerocklin,项目名称:qhash,代码行数:60,代码来源:qhash.go


示例4: calcHash

func calcHash(pass, salt []byte) []byte {
	h := sha512.New384()
	h.Write(hashVersion)
	h.Write(salt)
	h.Write(pass)
	return h.Sum(nil)
}
开发者ID:cmars,项目名称:shadowfax,代码行数:7,代码来源:main.go


示例5: checkGetArchive

func (s *suite) checkGetArchive(c *gc.C) string {
	ch := charmRepo.CharmArchive(c.MkDir(), "wordpress")

	// Open the archive and calculate its hash and size.
	r, expectHash, expectSize := archiveHashAndSize(c, ch.Path)
	r.Close()

	url := charm.MustParseReference("~charmers/utopic/wordpress-42")
	err := s.client.UploadCharmWithRevision(url, ch, 42)
	c.Assert(err, gc.IsNil)

	rb, id, hash, size, err := s.client.GetArchive(url)
	c.Assert(err, gc.IsNil)
	defer rb.Close()
	c.Assert(id, jc.DeepEquals, url)
	c.Assert(hash, gc.Equals, expectHash)
	c.Assert(size, gc.Equals, expectSize)

	h := sha512.New384()
	size, err = io.Copy(h, rb)
	c.Assert(err, gc.IsNil)
	c.Assert(size, gc.Equals, expectSize)
	c.Assert(fmt.Sprintf("%x", h.Sum(nil)), gc.Equals, expectHash)

	// Return the stats key for the archive download.
	keys := []string{params.StatsArchiveDownload, "utopic", "wordpress", "charmers", "42"}
	return strings.Join(keys, ":")
}
开发者ID:jrwren,项目名称:charmrepo,代码行数:28,代码来源:csclient_test.go


示例6: Checksum

// Checksum returns the checksum of some data, using a specified algorithm.
// It only returns an error when an invalid algorithm is used. The valid ones
// are MD5, SHA1, SHA224, SHA256, SHA384, SHA512, SHA3224, SHA3256, SHA3384,
// and SHA3512.
func Checksum(algorithm string, data []byte) (checksum string, err error) {
	// default
	var hasher hash.Hash
	switch strings.ToUpper(algorithm) {
	case "MD5":
		hasher = md5.New()
	case "SHA1":
		hasher = sha1.New()
	case "SHA224":
		hasher = sha256.New224()
	case "SHA256":
		hasher = sha256.New()
	case "SHA384":
		hasher = sha512.New384()
	case "SHA512":
		hasher = sha512.New()
	case "SHA3224":
		hasher = sha3.New224()
	case "SHA3256":
		hasher = sha3.New256()
	case "SHA3384":
		hasher = sha3.New384()
	case "SHA3512":
		hasher = sha3.New512()
	default:
		msg := "Invalid algorithm parameter passed go Checksum: %s"
		return checksum, fmt.Errorf(msg, algorithm)
	}
	hasher.Write(data)
	str := hex.EncodeToString(hasher.Sum(nil))
	return str, nil
}
开发者ID:allenbhuiyan,项目名称:distributive,代码行数:36,代码来源:fsstatus.go


示例7: main

func main() {
	for _, h := range []hash.Hash{md4.New(), md5.New(), sha1.New(),
		sha256.New224(), sha256.New(), sha512.New384(), sha512.New(),
		ripemd160.New()} {
		fmt.Printf("%x\n\n", h.Sum())
	}
}
开发者ID:sbhackerspace,项目名称:sbhx-snippets,代码行数:7,代码来源:hash.go


示例8: sha384

func (e *Engine) sha384() error {
	data, err := computeHash(sha512.New384(), e.stack.Pop())
	if err == nil {
		e.stack.Push(data)
	}
	return err
}
开发者ID:ancientlore,项目名称:hashsrv,代码行数:7,代码来源:hash.go


示例9: calc_checksum

/*
   read from os.File and return the whole file's checksum
*/
func calc_checksum(fp io.Reader, t string) string {
	var m hash.Hash
	switch t {
	case "md5":
		m = md5.New()
	case "sha1":
		m = sha1.New()
	case "sha512":
		m = sha512.New()
	case "sha256":
		m = sha256.New()
	case "sha224":
		m = sha256.New224()
	case "sha384":
		m = sha512.New384()
	default:
		output_e("unknown type: %s\n", t)
		return ""
	}

	/*  issue:
	    if fp is os.Stdin, there is no way to trigger EOF
	*/
	_, err := io.Copy(m, fp)

	if err != nil {
		output_e("%ssum: %s\n", t, err.Error())
		return ""
	}

	return fmt.Sprintf("%x", m.Sum(nil))
}
开发者ID:patrickToca,项目名称:go-coreutils,代码行数:35,代码来源:calc_sum.go


示例10: TestHashOpts

func TestHashOpts(t *testing.T) {
	msg := []byte("abcd")

	// SHA256
	digest1, err := currentBCCSP.Hash(msg, &bccsp.SHA256Opts{})
	if err != nil {
		t.Fatalf("Failed computing SHA256 [%s]", err)
	}

	h := sha256.New()
	h.Write(msg)
	digest2 := h.Sum(nil)

	if !bytes.Equal(digest1, digest2) {
		t.Fatalf("Different SHA256 computed. [%x][%x]", digest1, digest2)
	}

	// SHA384
	digest1, err = currentBCCSP.Hash(msg, &bccsp.SHA384Opts{})
	if err != nil {
		t.Fatalf("Failed computing SHA384 [%s]", err)
	}

	h = sha512.New384()
	h.Write(msg)
	digest2 = h.Sum(nil)

	if !bytes.Equal(digest1, digest2) {
		t.Fatalf("Different SHA384 computed. [%x][%x]", digest1, digest2)
	}

	// SHA3_256O
	digest1, err = currentBCCSP.Hash(msg, &bccsp.SHA3_256Opts{})
	if err != nil {
		t.Fatalf("Failed computing SHA3_256 [%s]", err)
	}

	h = sha3.New256()
	h.Write(msg)
	digest2 = h.Sum(nil)

	if !bytes.Equal(digest1, digest2) {
		t.Fatalf("Different SHA3_256 computed. [%x][%x]", digest1, digest2)
	}

	// SHA3_384
	digest1, err = currentBCCSP.Hash(msg, &bccsp.SHA3_384Opts{})
	if err != nil {
		t.Fatalf("Failed computing SHA3_384 [%s]", err)
	}

	h = sha3.New384()
	h.Write(msg)
	digest2 = h.Sum(nil)

	if !bytes.Equal(digest1, digest2) {
		t.Fatalf("Different SHA3_384 computed. [%x][%x]", digest1, digest2)
	}
}
开发者ID:hyperledger,项目名称:fabric,代码行数:59,代码来源:impl_test.go


示例11: ToDS

// ToDS converts a DNSKEY record to a DS record.
func (k *RR_DNSKEY) ToDS(h int) *RR_DS {
	if k == nil {
		return nil
	}
	ds := new(RR_DS)
	ds.Hdr.Name = k.Hdr.Name
	ds.Hdr.Class = k.Hdr.Class
	ds.Hdr.Rrtype = TypeDS
	ds.Hdr.Ttl = k.Hdr.Ttl
	ds.Algorithm = k.Algorithm
	ds.DigestType = uint8(h)
	ds.KeyTag = k.KeyTag()

	keywire := new(dnskeyWireFmt)
	keywire.Flags = k.Flags
	keywire.Protocol = k.Protocol
	keywire.Algorithm = k.Algorithm
	keywire.PublicKey = k.PublicKey
	wire := make([]byte, DefaultMsgSize)
	n, ok := PackStruct(keywire, wire, 0)
	if !ok {
		return nil
	}
	wire = wire[:n]

	owner := make([]byte, 255)
	off, ok1 := PackDomainName(k.Hdr.Name, owner, 0, nil, false)
	if !ok1 {
		return nil
	}
	owner = owner[:off]
	// RFC4034:
	// digest = digest_algorithm( DNSKEY owner name | DNSKEY RDATA);
	// "|" denotes concatenation
	// DNSKEY RDATA = Flags | Protocol | Algorithm | Public Key.

	// digest buffer
	digest := append(owner, wire...) // another copy

	switch h {
	case SHA1:
		s := sha1.New()
		io.WriteString(s, string(digest))
		ds.Digest = hex.EncodeToString(s.Sum(nil))
	case SHA256:
		s := sha256.New()
		io.WriteString(s, string(digest))
		ds.Digest = hex.EncodeToString(s.Sum(nil))
	case SHA384:
		s := sha512.New384()
		io.WriteString(s, string(digest))
		ds.Digest = hex.EncodeToString(s.Sum(nil))
	case GOST94:
		/* I have no clue */
	default:
		return nil
	}
	return ds
}
开发者ID:wallrat,项目名称:dns,代码行数:60,代码来源:dnssec.go


示例12: calculateCheckSum

func calculateCheckSum(c *gc.C, start, length int64, blob []byte) (sha384HashHex string) {
	data := blob[start : start+length]
	sha384Hash := sha512.New384()
	_, err := sha384Hash.Write(data)
	c.Assert(err, gc.IsNil)
	sha384HashHex = fmt.Sprintf("%x", sha384Hash.Sum(nil))
	return sha384HashHex
}
开发者ID:juju,项目名称:blobstore,代码行数:8,代码来源:managedstorage_test.go


示例13: newFingerprint

func newFingerprint(c *gc.C, data string) ([]byte, string) {
	hash := sha512.New384()
	_, err := hash.Write([]byte(data))
	c.Assert(err, jc.ErrorIsNil)
	sum := hash.Sum(nil)

	hexStr := hex.EncodeToString(sum)
	return sum, hexStr
}
开发者ID:juju,项目名称:utils,代码行数:9,代码来源:fingerprint_test.go


示例14: archiveHashAndSize

func archiveHashAndSize(c *gc.C, path string) (r csclient.ReadSeekCloser, hash string, size int64) {
	f, err := os.Open(path)
	c.Assert(err, gc.IsNil)
	h := sha512.New384()
	size, err = io.Copy(h, f)
	c.Assert(err, gc.IsNil)
	_, err = f.Seek(0, 0)
	c.Assert(err, gc.IsNil)
	return f, fmt.Sprintf("%x", h.Sum(nil)), size
}
开发者ID:jrwren,项目名称:charmrepo,代码行数:10,代码来源:csclient_test.go


示例15: hashAlg

func hashAlg(keySizeBits int) hash.Hash {
	switch keySizeBits {
	case 256:
		return sha256.New()
	case 384:
		return sha512.New384()
	default:
		return sha512.New()
	}
}
开发者ID:szank,项目名称:jose2go,代码行数:10,代码来源:sha.go


示例16: prf

func (alg *Pbse2HmacAesKW) prf() hash.Hash {
	switch alg.keySizeBits {
	case 128:
		return sha256.New()
	case 192:
		return sha512.New384()
	default:
		return sha512.New()
	}
}
开发者ID:useidel,项目名称:notary,代码行数:10,代码来源:pbse2_hmac_aeskw.go


示例17: hash

func (d *Deduper) hash(data []byte, rest ...[]byte) (hash [HashSize]byte) {
	h := sha512.New384()
	h.Write(data)
	for _, d := range rest {
		h.Write(d)
	}
	s := h.Sum(nil)
	copy(hash[:], s[:HashSize])
	return
}
开发者ID:jwatt,项目名称:kythe,代码行数:10,代码来源:dedup.go


示例18: readerHashAndSize

// readerHashAndSize returns the SHA384 and size of the data included in the
// given reader.
func readerHashAndSize(r io.ReadSeeker) (hash string, size int64, err error) {
	h := sha512.New384()
	size, err = io.Copy(h, r)
	if err != nil {
		return "", 0, errgo.Notef(err, "cannot calculate hash")
	}
	if _, err := r.Seek(0, 0); err != nil {
		return "", 0, errgo.Notef(err, "cannot seek")
	}
	return fmt.Sprintf("%x", h.Sum(nil)), size, nil
}
开发者ID:jrwren,项目名称:charmrepo,代码行数:13,代码来源:archive.go


示例19: macSHA384

func macSHA384(version uint16, key []byte) macFunction {
	if version == VersionSSL30 {
		mac := ssl30MAC{
			h:   sha512.New384(),
			key: make([]byte, len(key)),
		}
		copy(mac.key, key)
		return mac
	}
	return tls10MAC{hmac.New(sha512.New384, key)}
}
开发者ID:randombit,项目名称:hacrypto,代码行数:11,代码来源:cipher_suites.go


示例20: getPassphrase

func getPassphrase(prompt string) []byte {
	var h hash.Hash = sha512.New384()
	fmt.Fprintf(os.Stdout, prompt)
	phrase, err := terminal.ReadPassword(int(os.Stdin.Fd()))
	fmt.Fprintf(os.Stdout, "\n")
	if err != nil {
		log.Fatal(err)
	}
	io.Copy(h, bytes.NewReader(phrase))
	return h.Sum(nil)
}
开发者ID:hdonnay,项目名称:vaultd,代码行数:11,代码来源:vault.go



注:本文中的crypto/sha512.New384函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang sha512.Sum384函数代码示例发布时间:2022-05-24
下一篇:
Golang sha512.New函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap