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

Golang sha512.Sum384函数代码示例

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

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



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

示例1: GetAddress

// 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
}
开发者ID:msecret,项目名称:emp,代码行数:29,代码来源:address.go


示例2: _passpharseHash

func _passpharseHash(passpharse []byte, encodingWay []string) (encodedpasspharse []byte) {
	encodepasspharse := passpharse
	for _, hashalgor := range encodingWay {
		switch hashalgor {
		case "md5":
			sum := md5.Sum(encodepasspharse)
			encodepasspharse = sum[:]
		case "sha1":
			sum := sha1.Sum(encodepasspharse)
			encodepasspharse = sum[:]
		case "sha224":
			sum := sha256.Sum224(encodepasspharse)
			encodepasspharse = sum[:]
		case "sha256":
			sum := sha256.Sum256(encodepasspharse)
			encodepasspharse = sum[:]
		case "sha384":
			sum := sha512.Sum384(encodepasspharse)
			encodepasspharse = sum[:]
		case "sha512":
			sum := sha512.Sum512(encodepasspharse)
			encodepasspharse = sum[:]
		}
	}
	//issue if return with not args,the return value will be null
	return encodepasspharse
}
开发者ID:wulinxu,项目名称:KeyAdmin-go,代码行数:27,代码来源:passwordadmin.go


示例3: main

func main() {
	flag.Parse()
	if len(flag.Args()) != 0 {
		flagutil.UsageErrorf("unknown arguments: %v", flag.Args())
	}

	written := make(map[[sha512.Size384]byte]struct{})

	var skipped uint64
	rd := delimited.NewReader(os.Stdin)
	wr := delimited.NewWriter(os.Stdout)
	for {
		rec, err := rd.Next()
		if err == io.EOF {
			break
		} else if err != nil {
			log.Fatal(err)
		}

		hash := sha512.Sum384(rec)
		if _, ok := written[hash]; ok {
			skipped++
			continue
		}
		if err := wr.Put(rec); err != nil {
			log.Fatal(err)
		}
		written[hash] = struct{}{}
	}
	log.Printf("dedup_stream: skipped %d records", skipped)
}
开发者ID:gameduell,项目名称:kythe,代码行数:31,代码来源:dedup_stream.go


示例4: AddPurge

// Add Purge Token to database, and remove corresponding message if necessary.
func AddPurge(log chan string, p objects.Purge) error {
	mutex.Lock()
	defer mutex.Unlock()

	txid := p.GetBytes()
	hashArr := sha512.Sum384(txid)
	hash := hashArr[:]

	if hashList == nil || dbConn == nil {
		return DBError(EUNINIT)
	}
	hashObj := new(objects.Hash)
	hashObj.FromBytes(hash)

	if Contains(*hashObj) == PURGE {
		return nil
	}

	err := dbConn.Exec("INSERT INTO purge VALUES (?, ?)", hash, txid)
	if err != nil {
		log <- fmt.Sprintf("Error inserting purge into db... %s", err)
		return err
	}

	Add(*hashObj, PURGE)
	return nil
}
开发者ID:msecret,项目名称:emp,代码行数:28,代码来源:objects.go


示例5: main

func main() {
	length := len(os.Args)
	if length > 2 {
		if os.Args[2] == "-384" {
			c1 := sha512.Sum384([]byte(os.Args[1]))
			fmt.Printf("%s\n%x\n%T\n", os.Args[1], c1, c1)
		} else if os.Args[2] == "-512" {
			c1 := sha512.Sum512([]byte(os.Args[1]))
			fmt.Printf("%s\n%x\n%T\n", os.Args[1], c1, c1)
		} else {
			c1 := sha256.Sum256([]byte(os.Args[1]))
			fmt.Printf("%s\n%x\n%T\n", os.Args[1], c1, c1)
		}
	} else if length == 2 {
		c1 := sha256.Sum256([]byte(os.Args[1]))
		fmt.Printf("%s\n%x\n%T\n", os.Args[1], c1, c1)
	} else {
		fmt.Printf("less arguments")
	}
	// Output:
	// 2d711642b726b04401627ca9fbac32f5c8530fb1903cc4db02258717921a4881
	// 4b68ab3847feda7d6c62c1fbcbeebfa35eab7351ed5e78f4ddadea5df64b8015
	// false
	// [32]uint8
}
开发者ID:Esper0328,项目名称:Go_training,代码行数:25,代码来源:main.go


示例6: BaseLayerID

// BaseLayerID returns the 64 byte hex ID for the baselayer name.
func (r *RootFS) BaseLayerID() string {
	if r.Type != TypeLayersWithBase {
		panic("tried to get base layer ID without a base layer")
	}
	baseID := sha512.Sum384([]byte(r.BaseLayer))
	return fmt.Sprintf("%x", baseID[:32])
}
开发者ID:CadeLaRen,项目名称:docker-3,代码行数:8,代码来源:rootfs_windows.go


示例7: ValidateAddress

// Determine if address is valid (checksum is correct, correct length, and it starts with a 1-byte number).
func ValidateAddress(addr []byte) bool {
	if len(addr) != 25 {
		return false
	}
	ripe := addr[:21]
	sum := sha512.Sum384(ripe)
	sum = sha512.Sum384(sum[:])

	for i := 0; i < 4; i++ {
		if sum[i] != addr[i+21] {
			return false
		}
	}

	return true
}
开发者ID:msecret,项目名称:emp,代码行数:17,代码来源:address.go


示例8: main

func main() {
	usage := "Usage: echo -n hello | ./ex02 [256|384|512]"
	bytes, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	n := 256
	if len(os.Args) == 2 {
		n, _ = strconv.Atoi(os.Args[1])
	}

	switch n {
	case 256:
		fmt.Printf("%x\n", sha256.Sum256(bytes))
		os.Exit(0)
		return
	case 384:
		fmt.Printf("%x\n", sha512.Sum384(bytes))
		os.Exit(0)
		return
	case 512:
		fmt.Printf("%x\n", sha512.Sum512(bytes))
		os.Exit(0)
		return
	default:
		fmt.Println(usage)
		os.Exit(1)
		return
	}
}
开发者ID:sonedazaurus,项目名称:golang-training,代码行数:31,代码来源:main.go


示例9: Run

func (c *CLI) Run(args []string) int {
	flagSet := flag.NewFlagSet(args[0], flag.ExitOnError)
	flagSet.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage of %s:\n", args[0])
		flagSet.PrintDefaults()
	}
	hashType := flagSet.String("type", "sha256", "Hash algorithm (sha256, sha384 or sha512)")

	if err := flagSet.Parse(args[1:]); err != nil {
		return ExitCodeParseFlagError
	}

	bytes, err := ioutil.ReadAll(c.inStream)
	if err != nil {
		return ReadStdinError
	}

	switch *hashType {
	case "sha256":
		fmt.Fprintf(c.outStream, "%x\n", sha256.Sum256(bytes))
	case "sha384":
		fmt.Fprintf(c.outStream, "%x\n", sha512.Sum384(bytes))
	case "sha512":
		fmt.Fprintf(c.outStream, "%x\n", sha512.Sum512(bytes))
	default:
		flagSet.Usage()
		return ExitCodeParseFlagError
	}
	return ExitCodeOK
}
开发者ID:seikichi,项目名称:gopl,代码行数:30,代码来源:main.go


示例10: verify

func verify(pub *ecdsa.PublicKey, data, sig []byte) bool {
	var unpackedSig ECDSASignature
	_, err := asn1.Unmarshal(sig, &unpackedSig)
	if err != nil {
		return false
	}
	h := sha512.Sum384(data)
	return ecdsa.Verify(pub, h[:], unpackedSig.R, unpackedSig.S)
}
开发者ID:postfix,项目名称:arx,代码行数:9,代码来源:crypto.go


示例11: _createpasswd

// 返回值:长度120
func _createpasswd(salt, passwd []byte) string {
	var orig []byte

	orig = append(salt, passwd...)
	orig = append(orig, _secret...)
	hsh := sha512.Sum384(orig)

	return hex.EncodeToString(append(salt, hsh[:]...))
}
开发者ID:smtc,项目名称:justTalk,代码行数:10,代码来源:password.go


示例12: GetCustomImageInfos

// GetCustomImageInfos returns the image infos for window specific
// base images which should always be present.
func (d *Driver) GetCustomImageInfos() ([]CustomImageInfo, error) {
	strData, err := hcsshim.GetSharedBaseImages()
	if err != nil {
		return nil, fmt.Errorf("Failed to restore base images: %s", err)
	}

	type customImageInfoList struct {
		Images []CustomImageInfo
	}

	var infoData customImageInfoList

	if err = json.Unmarshal([]byte(strData), &infoData); err != nil {
		err = fmt.Errorf("JSON unmarshal returned error=%s", err)
		logrus.Error(err)
		return nil, err
	}

	var images []CustomImageInfo

	for _, imageData := range infoData.Images {
		folderName := filepath.Base(imageData.Path)

		// Use crypto hash of the foldername to generate a docker style id.
		h := sha512.Sum384([]byte(folderName))
		id := fmt.Sprintf("%x", h[:32])

		if err := d.Create(id, "", "", nil); err != nil {
			return nil, err
		}
		// Create the alternate ID file.
		if err := d.setID(id, folderName); err != nil {
			return nil, err
		}

		imageData.ID = id

		// For now, hard code that all base images except nanoserver depend on win32k support
		if imageData.Name != "NanoServer" {
			imageData.OSFeatures = append(imageData.OSFeatures, "win32k")
		}

		versionData := strings.Split(imageData.Version, ".")
		if len(versionData) != 4 {
			logrus.Warn("Could not parse Windows version %s", imageData.Version)
		} else {
			// Include just major.minor.build, skip the fourth version field, which does not influence
			// OS compatibility.
			imageData.OSVersion = strings.Join(versionData[:3], ".")
		}

		images = append(images, imageData)
	}

	return images, nil
}
开发者ID:errordeveloper,项目名称:docker,代码行数:58,代码来源:windows.go


示例13: hashBySHA

func hashBySHA(s string, size int) {
	switch size {
	case 384:
		fmt.Printf("%x\n", sha512.Sum384([]byte(s)))
	case 512:
		fmt.Printf("%x\n", sha512.Sum512([]byte(s)))
	default:
		fmt.Printf("%x\n", sha256.Sum256([]byte(s)))
	}
}
开发者ID:yksz,项目名称:go-training,代码行数:10,代码来源:sha2.go


示例14: sign

func sign(priv *ecdsa.PrivateKey, data []byte) ([]byte, error) {
	var sig ECDSASignature
	var err error

	h := sha512.Sum384(data)
	sig.R, sig.S, err = ecdsa.Sign(prng, priv, h[:])
	if err != nil {
		return nil, err
	}
	return asn1.Marshal(sig)
}
开发者ID:postfix,项目名称:arx,代码行数:11,代码来源:crypto.go


示例15: main

func main() {

	flag.Parse()

	if *t {
		fmt.Printf("SHA384 = %x\n", sha512.Sum384([]byte(os.Args[1])))
	} else if *f {
		fmt.Printf("SHA512 = %x\n", sha512.Sum512([]byte(os.Args[1])))
	} else {
		fmt.Printf("SHA256 = %x\n", sha256.Sum256([]byte(os.Args[1])))
	}
}
开发者ID:dugwill,项目名称:gopl.io,代码行数:12,代码来源:main.go


示例16: main

func main() {
	var useType string
	flag.StringVar(&useType, "sha", "256", "256, 384, 512. ")
	flag.Parse()

	arg := []byte(flag.Arg(0))
	switch useType {
	case "384":
		fmt.Printf("%x\n", sha512.Sum384(arg))
	case "512":
		fmt.Printf("%x\n", sha512.Sum512(arg))
	default:
		fmt.Printf("%x\n", sha256.Sum256(arg))
	}
}
开发者ID:utahta,项目名称:gopl,代码行数:15,代码来源:ex42.go


示例17: main

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		switch hash {
		case "sha384":
			c := sha512.Sum384(scanner.Bytes())
			fmt.Printf("%x\n", c)
		case "sha512":
			c := sha512.Sum512(scanner.Bytes())
			fmt.Printf("%x\n", c)
		default:
			c := sha256.Sum256(scanner.Bytes())
			fmt.Printf("%x\n", c)
		}
	}
}
开发者ID:ysohta,项目名称:gopl-ex,代码行数:16,代码来源:main.go


示例18: calcSHA

func calcSHA(s, opt string) []byte {
	switch opt {
	case "256":
		res := sha256.Sum256([]byte(s))
		return res[:]
	case "384":
		res := sha512.Sum384([]byte(s))
		return res[:]
	case "512":
		res := sha512.Sum512([]byte(s))
		return res[:]
	default:
		fmt.Println("undefined option.")
		return []byte{}
	}
}
开发者ID:y0k0ta19,项目名称:golang_training,代码行数:16,代码来源:calcSHA.go


示例19: main

func main() {
	flag.Parse()
	var b []byte
	fmt.Printf("input string to see its SHA%d: ", *bit)
	fmt.Scanln(&b)

	switch *bit {
	case 256:
		fmt.Fprintf(os.Stdout, "%x", sha256.Sum256(b))
	case 384:
		fmt.Fprintf(os.Stdout, "%x", sha512.Sum384(b))
	case 512:
		fmt.Fprintf(os.Stdout, "%x", sha512.Sum512(b))
	default:
		fmt.Fprintf(os.Stderr, "unsupported bit")
	}
}
开发者ID:yyBeta,项目名称:gopl,代码行数:17,代码来源:ex2.go


示例20: main

func main() {
	flag.Parse()
	b, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		panic(err)
	}
	switch *bit {
	case 256:
		fmt.Fprintf(os.Stdout, "%x", sha256.Sum256(b))
	case 384:
		fmt.Fprintf(os.Stdout, "%x", sha512.Sum384(b))
	case 512:
		fmt.Fprintf(os.Stdout, "%x", sha512.Sum512(b))
	default:
		fmt.Fprint(os.Stderr, "unsupported bit")
	}
}
开发者ID:suzuken,项目名称:gopl,代码行数:17,代码来源:ex2.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang sha512.Sum512函数代码示例发布时间:2022-05-24
下一篇:
Golang sha512.New384函数代码示例发布时间: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