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

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

示例1: pubkeyFromSeckey

//intenal, may fail
//may return nil
func pubkeyFromSeckey(seckey []byte) []byte {
    if len(seckey) != 32 {
        log.Panic("seckey length invalid")
    }

    if secp.SeckeyIsValid(seckey) != 1 {
        log.Panic("always ensure seckey is valid")
        return nil
    }

    var pubkey []byte = secp.GeneratePublicKey(seckey) //always returns true
    if pubkey == nil {
        log.Panic("ERROR: impossible, secp.BaseMultiply always returns true")
        return nil
    }
    if len(pubkey) != 33 {
        log.Panic("ERROR: impossible, invalid pubkey length")
    }

    if ret := secp.PubkeyIsValid(pubkey); ret != 1 {
        log.Panic("ERROR: pubkey invald, ret=%s", ret)
        return nil
    }

    if ret := VerifyPubkey(pubkey); ret != 1 {

        log.Printf("seckey= %s", hex.EncodeToString(seckey))
        log.Printf("pubkey= %s", hex.EncodeToString(pubkey))
        log.Panic("ERROR: pubkey verification failed, for deterministic. ret=%d", ret)
        return nil
    }

    return pubkey
}

开发者ID:keepwalking1234,项目名称:skycoin,代码行数:36,代码来源:secp256k1.go

示例2: hashFile

// Generate a human readable sha1 hash of the given file path
func hashFile(path string) (hashes FileInfo, err error) {
    f, err := os.Open(path)
    if err != nil {
        return
    }
    defer f.Close()

    reader := bufio.NewReader(f)

    if GetConfig().Hashes.SHA1 {
        sha1Hash := sha1.New()
        _, err = io.Copy(sha1Hash, reader)
        if err == nil {
            hashes.Sha1 = hex.EncodeToString(sha1Hash.Sum(nil))
        }
    }
    if GetConfig().Hashes.SHA256 {
        sha256Hash := sha256.New()
        _, err = io.Copy(sha256Hash, reader)
        if err == nil {
            hashes.Sha256 = hex.EncodeToString(sha256Hash.Sum(nil))
        }
    }
    if GetConfig().Hashes.MD5 {
        md5Hash := md5.New()
        _, err = io.Copy(md5Hash, reader)
        if err == nil {
            hashes.Md5 = hex.EncodeToString(md5Hash.Sum(nil))
        }
    }
    return
}

开发者ID:ninetian,项目名称:mirrorbits,代码行数:33,代码来源:utils.go

示例3: loginClassic

func (socket *mongoSocket) loginClassic(cred Credential) error {
    // Note that this only works properly because this function is
    // synchronous, which means the nonce won't get reset while we're
    // using it and any other login requests will block waiting for a
    // new nonce provided in the defer call below.
    nonce, err := socket.getNonce()
    if err != nil {
        return err
    }
    defer socket.resetNonce()

    psum := md5.New()
    psum.Write([]byte(cred.Username + ":mongo:" + cred.Password))

    ksum := md5.New()
    ksum.Write([]byte(nonce + cred.Username))
    ksum.Write([]byte(hex.EncodeToString(psum.Sum(nil))))

    key := hex.EncodeToString(ksum.Sum(nil))

    cmd := authCmd{Authenticate: 1, User: cred.Username, Nonce: nonce, Key: key}
    res := authResult{}
    return socket.loginRun(cred.Source, &cmd, &res, func() error {
        if !res.Ok {
            return errors.New(res.ErrMsg)
        }
        socket.Lock()
        socket.dropAuth(cred.Source)
        socket.creds = append(socket.creds, cred)
        socket.Unlock()
        return nil
    })
}

开发者ID:NotBlizzard,项目名称:bluebirdmini,代码行数:33,代码来源:auth.go

示例4: introduceVia

func (mod *module) introduceVia(router *e3x.Exchange, to hashname.H) error {
    localIdent, err := mod.e.LocalIdentity()
    if err != nil {
        return err
    }

    keys := localIdent.Keys()
    parts := hashname.PartsFromKeys(keys)

    for csid, key := range keys {
        inner := lob.New(key.Public())
        for partCSID, part := range parts {
            if partCSID == csid {
                inner.Header().SetBool(hex.EncodeToString([]byte{partCSID}), true)
            } else {
                inner.Header().SetString(hex.EncodeToString([]byte{partCSID}), part)
            }
        }

        body, err := lob.Encode(inner)
        if err != nil {
            return err
        }

        err = mod.peerVia(router, to, body)
        if err != nil {
            return err
        }
    }

    return nil
}

开发者ID:utamaro,项目名称:gogotelehash,代码行数:32,代码来源:channel_peer.go

示例5: Response

// Response is called by the HTTP server to handle a new OCSP request.
func (src *DBSource) Response(req *ocsp.Request) (response []byte, present bool) {
    log := blog.GetAuditLogger()

    // Check that this request is for the proper CA
    if bytes.Compare(req.IssuerKeyHash, src.caKeyHash) != 0 {
        log.Debug(fmt.Sprintf("Request intended for CA Cert ID: %s", hex.EncodeToString(req.IssuerKeyHash)))
        present = false
        return
    }

    serialString := core.SerialToString(req.SerialNumber)
    log.Debug(fmt.Sprintf("Searching for OCSP issued by us for serial %s", serialString))

    var ocspResponse core.OCSPResponse
    // Note: we order by id rather than createdAt, because otherwise we sometimes
    // get the wrong result if a certificate is revoked in the same second as its
    // last update (e.g. client issues and instant revokes).
    err := src.dbMap.SelectOne(&ocspResponse, "SELECT * from ocspResponses WHERE serial = :serial ORDER BY id DESC LIMIT 1;",
        map[string]interface{}{"serial": serialString})
    if err != nil {
        present = false
        return
    }

    log.Info(fmt.Sprintf("OCSP Response sent for CA=%s, Serial=%s", hex.EncodeToString(src.caKeyHash), serialString))

    response = ocspResponse.Response
    present = true
    return
}

开发者ID:sjas,项目名称:boulder,代码行数:31,代码来源:main.go

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