當前位置: 首頁>>代碼示例>>Golang>>正文


Golang sha1.Write函數代碼示例

本文整理匯總了Golang中crypto/sha1.Write函數的典型用法代碼示例。如果您正苦於以下問題:Golang Write函數的具體用法?Golang Write怎麽用?Golang Write使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Write函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: getScramble

func getScramble(keyA *big.Int, keyB *big.Int) *big.Int {
	// keyA:A client public ephemeral values
	// keyB:B server public ephemeral values

	sha1 := sha1.New()
	sha1.Write(pad(keyA))
	sha1.Write(pad(keyB))

	return bytesToBig(sha1.Sum(nil))
}
開發者ID:kleopatra999,項目名稱:firebirdsql,代碼行數:10,代碼來源:srp.go

示例2: main

func main() {
	fmt.Println("Start...")
	// String from:
	// http://en.wikipedia.org/wiki/WebSocket
	s := "x3JJHMbDL1EzLkh9GBhXDw==258EAFA5-E914-47DA-95CA-C5AB0DC85B11"

	// sha1 stuff ...
	sha1 := sha1.New()
	sha1.Write([]byte(s))
	ss := fmt.Sprintf("%x", sha1.Sum(nil))
	fmt.Printf("%s\n", ss)
	w := "1d29ab734b0c9585240069a6e4e3e91b61da1969"
	fmt.Printf("%s\n", w)
	if ss != w {
		panic("Uh oh, something is not right")
	}
	// ---------------------------------------------------------------------------
	// The base64 encoding part of that post is left as an exercise for now.
	// From the article the base64 result should be:
	// HSmrc0sMlYUkAGmm5OPpG2HaGWk=
	// *not tested*
	// ---------------------------------------------------------------------------
	// sha256 stuff ...
	sha256 := sha256.New()
	sha256.Write([]byte(s))
	ss = fmt.Sprintf("%x", sha256.Sum(nil))
	fmt.Printf("%s\n", ss)
	fmt.Println("End...")
}
開發者ID:ra,項目名稱:go-samp,代碼行數:29,代碼來源:shax.go

示例3: CalcStrong

// Calculate the strong checksum of a directory.
func CalcStrong(dir Dir) string {
	var sha1 = sha1.New()
	//	s := reprDir(dir)
	//	fmt.Printf("%s\n", s)
	//	sha1.Write(s)
	sha1.Write(reprDir(dir))
	return toHexString(sha1)
}
開發者ID:cmars,項目名稱:replican-sync,代碼行數:9,代碼來源:node.go

示例4: IndexFile

// Build a hierarchical tree model representing a file's contents
func IndexFile(path string) (file *File, err error) {
	var f *os.File
	var buf [BLOCKSIZE]byte

	stat, err := os.Stat(path)
	if stat == nil {
		return nil, err
	} else if !stat.IsRegular() {
		return nil, errors.New(fmt.Sprintf("%s: not a regular file", path))
	}

	f, err = os.Open(path)
	if f == nil {
		return nil, err
	}
	defer f.Close()

	file = new(File)
	_, basename := filepath.Split(path)
	file.name = basename
	file.mode = stat.Mode

	if fileInfo, err := f.Stat(); fileInfo != nil {
		file.Size = fileInfo.Size
	} else {
		return nil, err
	}

	var block *Block
	sha1 := sha1.New()
	blockNum := 0

	for {
		switch rd, err := f.Read(buf[:]); true {
		case rd < 0:
			return nil, err
		case rd == 0:
			file.strong = toHexString(sha1)
			return file, nil
		case rd > 0:
			// Update block hashes
			block = IndexBlock(buf[0:rd])
			block.position = blockNum
			file.Blocks = append(file.Blocks, block)

			// update file hash
			sha1.Write(buf[0:rd])

			// Increment block counter
			blockNum++
		}
	}

	return nil, nil
}
開發者ID:vanackere,項目名稱:replican-sync,代碼行數:56,代碼來源:index.go

示例5: b64sha1

func b64sha1(data []byte) string {
	sha1 := sha1.New()
	sha1.Write(data)
	hash := sha1.Sum(nil)

	b := new(bytes.Buffer)
	b64 := base64.NewEncoder(base64.URLEncoding, b)
	b64.Write(hash)

	return b.String()
}
開發者ID:kylelemons,項目名稱:gopaste,代碼行數:11,代碼來源:paste.go

示例6: generateId

// Generate a unique id as a base64 encoded string
func generateId() string {

	// Generate a random 128 bit Id
	z, err := rand.Int(rand.Reader, maxSessionId)
	if err != nil {
		log.Fatal("Cannot generate session id", err)
	}

	// Take the hash of the random id
	sha1 := sha1.New()
	sha1.Write(z.Bytes())

	return base64.StdEncoding.EncodeToString(sha1.Sum([]byte{}))
}
開發者ID:alienscience,項目名稱:bread,代碼行數:15,代碼來源:cookie.go

示例7: IndexFile

// Build a hierarchical tree model representing a file's contents
func IndexFile(path string) (fileInfo *FileInfo, blocksInfo []*BlockInfo, err os.Error) {
	var f *os.File
	var buf [BLOCKSIZE]byte

	stat, err := os.Stat(path)
	if stat == nil {
		return nil, nil, err
	} else if !stat.IsRegular() {
		return nil, nil, os.NewError(fmt.Sprintf("%s: not a regular file", path))
	}

	f, err = os.Open(path)
	if f == nil {
		return nil, nil, err
	}
	defer f.Close()

	_, basename := filepath.Split(path)
	fileInfo = &FileInfo{
		Name: basename,
		Mode: stat.Mode,
		Size: stat.Size}

	var block *BlockInfo
	sha1 := sha1.New()
	blockNum := 0
	blocksInfo = []*BlockInfo{}

	for {
		switch rd, err := f.Read(buf[:]); true {
		case rd < 0:
			return nil, nil, err
		case rd == 0:
			fileInfo.Strong = toHexString(sha1)
			return fileInfo, blocksInfo, nil
		case rd > 0:
			// Update block hashes
			block = IndexBlock(buf[0:rd])
			block.Position = blockNum
			blocksInfo = append(blocksInfo, block)

			// update file hash
			sha1.Write(buf[0:rd])

			// Increment block counter
			blockNum++
		}
	}
	panic("Impossible")
}
開發者ID:cmars,項目名稱:replican-sync,代碼行數:51,代碼來源:index.go

示例8: MojangSha1Hex

func MojangSha1Hex(arrBytes ...[]byte) (val string) {
	sha1 := sha1.New()
	for _, bytes := range arrBytes {
		sha1.Write(bytes)
	}
	hash := sha1.Sum(nil)
	negative := (hash[0] & 0x80) == 0x80
	if negative {
		twosCompliment(hash)
	}
	val = hex.EncodeToString(hash)
	val = strings.TrimLeft(val, "0")
	if negative {
		val = "-" + val
	}
	return
}
開發者ID:LivousCraftNetwork,項目名稱:GoLilyPad,代碼行數:17,代碼來源:util.go

示例9: MojangSha1Hex

func MojangSha1Hex(arrBytes ...[]byte) string {
	sha1 := sha1.New()
	for _, bytes := range arrBytes {
		sha1.Write(bytes)
	}
	hash := sha1.Sum(nil)
	negative := (hash[0] & 0x80) == 0x80
	if negative {
		twosCompliment(hash)
	}
	hexString := hex.EncodeToString(hash)
	hexString = strings.TrimLeft(hexString, "0")
	if negative {
		hexString = "-" + hexString
	}
	return hexString
}
開發者ID:Jumla,項目名稱:GoLilyPad,代碼行數:17,代碼來源:util.go

示例10: calcFileInfo

func calcFileInfo(fi *FileInfo) {
	fmt.Printf("calcFileInfo: '%s'\n", fi.Path)
	var buf [16 * 1024]byte
	r, err := os.Open(fi.Path)
	fataliferr(err)
	defer r.Close()
	sha1 := sha1.New()
	md5Hash := md5.New()
	fi.Size = 0
	for {
		n, err := r.Read(buf[:])
		if err == io.EOF {
			break
		}
		d := buf[:n]
		fataliferr(err)
		fatalif(n == 0, "n is 0")
		fi.Size += int64(n)
		_, err = sha1.Write(d)
		fataliferr(err)
		_, err = md5Hash.Write(d)
		fataliferr(err)
	}
	sha1Sum := sha1.Sum(nil)
	fi.Sha1Hex = fmt.Sprintf("%x", sha1Sum)

	md5Sum := md5Hash.Sum(nil)
	fi.Md5Hex = fmt.Sprintf("%x", md5Sum)
	fi.Md5B64 = base64.StdEncoding.EncodeToString(md5Sum)

	fi.S3PathSha1Part = sha1HexToS3Path(fi.Sha1Hex)
	ext := strings.ToLower(filepath.Ext(fi.Path))
	fi.S3FullPath = s3Dir + fi.S3PathSha1Part + ext
	fmt.Printf("  sha1: %s\n", fi.Sha1Hex)
	fmt.Printf("   md5: %s\n", fi.Md5Hex)
	fmt.Printf("   md5: %s\n", fi.Md5B64)
	fmt.Printf("    s3: %s\n", fi.S3FullPath)
	fmt.Printf("  size: %d\n", fi.Size)
}
開發者ID:cnhans,項目名稱:sumatrapdf,代碼行數:39,代碼來源:main.go

示例11: getClientProof

func getClientProof(user string, password string, salt []byte, keyA *big.Int, keyB *big.Int, keya *big.Int) (keyM []byte, keyK []byte) {
	// M = H(H(N) xor H(g), H(I), s, A, B, K)
	prime, g, _ := getPrime()
	keyK = getClientSession(user, password, salt, keyA, keyB, keya)

	n1 := bytesToBig(bigToSha1(prime))
	n2 := bytesToBig(bigToSha1(g))
	n3 := mathutil.ModPowBigInt(n1, n2, prime)
	n4 := getStringHash(user)
	sha1 := sha1.New()
	sha1.Write(n3.Bytes())
	sha1.Write(n4.Bytes())
	sha1.Write(salt)
	sha1.Write(keyA.Bytes())
	sha1.Write(keyB.Bytes())
	sha1.Write(keyK)
	keyM = sha1.Sum(nil)

	return keyM, keyK
}
開發者ID:kleopatra999,項目名稱:firebirdsql,代碼行數:20,代碼來源:srp.go

示例12: Sha1Hex

func Sha1Hex(str string) (val string) {
	sha1 := sha1.New()
	sha1.Write([]byte(str))
	val = hex.EncodeToString(sha1.Sum(nil))
	return
}
開發者ID:0xNiklas,項目名稱:GoLilyPad,代碼行數:6,代碼來源:util.go

示例13: main

func main() {
	flag.Parse()
	sha1 := sha1.New()
	sha1.Write([]byte(flag.Arg(0)))
	fmt.Printf("%x\n", sha1.Sum(nil))
}
開發者ID:cesarkuroiwa,項目名稱:golang,代碼行數:6,代碼來源:sha1.go

示例14: getSha1Str

func getSha1Str(reposig string) string {
	sha1 := sha1.New()
	sha1.Write([]byte(reposig))
	return fmt.Sprintf("%x", sha1.Sum(nil))
}
開發者ID:holygeek,項目名稱:rid,代碼行數:5,代碼來源:rid.go

示例15: bigToSha1

func bigToSha1(n *big.Int) []byte {
	sha1 := sha1.New()
	sha1.Write(n.Bytes())

	return sha1.Sum(nil)
}
開發者ID:kleopatra999,項目名稱:firebirdsql,代碼行數:6,代碼來源:srp.go


注:本文中的crypto/sha1.Write函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。