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

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

示例1: calcAes30Params

// Calculates the key and iv for AES decryption given a password and salt.
func calcAes30Params(pass []uint16, salt []byte) (key, iv []byte) {
    p := make([]byte, 0, len(pass)*2+len(salt))
    for _, v := range pass {
        p = append(p, byte(v), byte(v>>8))
    }
    p = append(p, salt...)

    hash := sha1.New()
    iv = make([]byte, 16)
    s := make([]byte, 0, hash.Size())
    for i := 0; i < hashRounds; i++ {
        hash.Write(p)
        hash.Write([]byte{byte(i), byte(i >> 8), byte(i >> 16)})
        if i%(hashRounds/16) == 0 {
            s = hash.Sum(s[:0])
            iv[i/(hashRounds/16)] = s[4*4+3]
        }
    }
    key = hash.Sum(s[:0])
    key = key[:16]

    for k := key; len(k) >= 4; k = k[4:] {
        k[0], k[1], k[2], k[3] = k[3], k[2], k[1], k[0]
    }
    return key, iv
}

开发者ID:shazow,项目名称:mog,代码行数:27,代码来源:archive15.go

示例2: readBlockHeader

// readBlockHeader returns the next block header in the archive.
// It will return io.EOF if there were no bytes read.
func (a *archive15) readBlockHeader() (*blockHeader15, error) {
    var err error
    b := a.buf[:7]
    r := a.v
    if a.encrypted {
        salt := a.buf[:saltSize]
        _, err = io.ReadFull(r, salt)
        if err != nil {
            return nil, err
        }
        key, iv := a.getKeys(salt)
        r = newAesDecryptReader(r, key, iv)
        err = readFull(r, b)
    } else {
        _, err = io.ReadFull(r, b)
    }
    if err != nil {
        return nil, err
    }

    crc := b.uint16()
    hash := crc32.NewIEEE()
    hash.Write(b)
    h := new(blockHeader15)
    h.htype = b.byte()
    h.flags = b.uint16()
    size := b.uint16()
    if size < 7 {
        return nil, errCorruptHeader
    }
    size -= 7
    if int(size) > cap(a.buf) {
        a.buf = readBuf(make([]byte, size))
    }
    h.data = a.buf[:size]
    if err := readFull(r, h.data); err != nil {
        return nil, err
    }
    hash.Write(h.data)
    if crc != uint16(hash.Sum32()) {
        return nil, errBadHeaderCrc
    }
    if h.flags&blockHasData > 0 {
        if len(h.data) < 4 {
            return nil, errCorruptHeader
        }
        h.dataSize = int64(h.data.uint32())
    }
    if h.htype == blockService && h.flags&fileLargeData > 0 {
        if len(h.data) < 25 {
            return nil, errCorruptHeader
        }
        b := h.data[21:25]
        h.dataSize |= int64(b.uint32()) << 32
    }
    return h, nil
}

开发者ID:shazow,项目名称:mog,代码行数:59,代码来源:archive15.go

示例3: PBKDF2

// An implementation of PBKDF2 (Password-Based Key Derivation Function 2) as
// specified in PKCS #5 v2.0 from RSA Laboratorie and in `RFC 2898
// <http://www.ietf.org/rfc/rfc2898.txt>`.
func PBKDF2(hashfunc func([]byte) hash.Hash, password, salt []byte, iterations, keylen int) (key []byte) {

    var (
        digest          []byte
        i, j, k, length int
    )

    key = make([]byte, keylen)
    slice := key

    hash := hashfunc(password)
    hashlen := hash.Size()
    scratch := make([]byte, 4)

    for keylen > 0 {

        if hashlen > keylen {
            length = keylen
        } else {
            length = hashlen
        }

        i += 1

        scratch[0] = byte(i >> 24)
        scratch[1] = byte(i >> 16)
        scratch[2] = byte(i >> 8)
        scratch[3] = byte(i)

        hash.Write(salt)
        hash.Write(scratch)

        digest = hash.Sum()
        hash.Reset()

        for j = 0; j < length; j++ {
            slice[j] = digest[j]
        }

        for k = 1; k < iterations; k++ {
            hash.Write(digest)
            digest = hash.Sum()
            for j = 0; j < length; j++ {
                slice[j] ^= digest[j]
            }
            hash.Reset()
        }

        keylen -= length
        slice = slice[length:]

    }

    return

}

开发者ID:gitreview,项目名称:ampify,代码行数:59,代码来源:crypto.go

示例4: hashForChannelID

// hashForChannelID returns the hash to be signed for TLS Channel
// ID. If a resumption, resumeHash has the previous handshake
// hash. Otherwise, it is nil.
func (h finishedHash) hashForChannelID(resumeHash []byte) []byte {
    hash := sha256.New()
    hash.Write(channelIDLabel)
    if resumeHash != nil {
        hash.Write(channelIDResumeLabel)
        hash.Write(resumeHash)
    }
    hash.Write(h.server.Sum(nil))
    return hash.Sum(nil)
}

开发者ID:endlessm,项目名称:chromium-browser,代码行数:13,代码来源:prf.go

示例5: encrypt

// | signature | deadline | str
func (c *Cipher) encrypt(deadline uint64, b []byte) []byte {
    result := make([]byte, c.hdrLen+len(b))
    binary.BigEndian.PutUint64(result[c.sigLen:c.hdrLen], deadline)
    copy(result[c.hdrLen:], b)

    hash := hmac.New(c.hash, c.signKey)
    hash.Write(b)
    hash.Write(result[c.sigLen:c.hdrLen])
    copy(result, hash.Sum(nil)[:c.sigLen])

    return result
}

开发者ID:sshitaime,项目名称:gohper,代码行数:13,代码来源:token.go

最后编辑: kuteng  文档更新时间: 2021-08-23 19:14   作者:kuteng