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

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

示例1: LoadCertsKeys

func LoadCertsKeys(uname string, upass []byte) (ca []byte, ee []byte, pkey []byte, err error) {
    user_dir := common.GetConfDir(uname)
    cafs, err := ioutil.ReadFile(filepath.Join(user_dir, "ca.cert"))
    if err != nil {
        return nil, nil, nil, err
    }
    ca, err = passcrypto.DecryptMeBase32(string(cafs), upass)
    if err != nil {
        return nil, nil, nil, err
    }
    ee_pem, err := ioutil.ReadFile(filepath.Join(user_dir, "ee.cert"))
    if err != nil {
        return nil, nil, nil, err
    }
    ee_blk, _ := pem.Decode(ee_pem)
    ee = ee_blk.Bytes
    pkeyfs, err := ioutil.ReadFile(filepath.Join(user_dir, "ee.key"))
    if err != nil {
        return nil, nil, nil, err
    }
    pkey_pem, _ := pem.Decode(pkeyfs)
    pkey, err = x509.DecryptPEMBlock(pkey_pem, upass)
    if err != nil {
        return nil, nil, nil, err
    }
    return
}

开发者ID:hujun-open,项目名称:manpass,代码行数:27,代码来源:transport.go

示例2: init

func init() {
    var err error
    var pemBytes []byte
    var key crypto.Signer
    var p *pem.Block

    s, err = NewServerFromFile(certFile, keyFile, caFile, addr, os.Stdout)
    if err != nil {
        log.Fatal(err)
    }

    if pemBytes, err = ioutil.ReadFile(rsaPrivKey); err != nil {
        log.Fatal(err)
    }
    p, _ = pem.Decode(pemBytes)
    if key, err = x509.ParsePKCS1PrivateKey(p.Bytes); err != nil {
        log.Fatal(err)
    }
    s.RegisterKey(key)

    if pemBytes, err = ioutil.ReadFile(ecdsaPrivKey); err != nil {
        log.Fatal(err)
    }
    p, _ = pem.Decode(pemBytes)
    if key, err = x509.ParseECPrivateKey(p.Bytes); err != nil {
        log.Fatal(err)
    }
    s.RegisterKey(key)
}

开发者ID:AnonSuite,项目名称:gokeyless,代码行数:29,代码来源:server_test.go

示例3: TestExportKeysByID

func TestExportKeysByID(t *testing.T) {
    setUp(t)
    tempBaseDir, err := ioutil.TempDir("", "notary-test-")
    require.NoError(t, err)
    defer os.RemoveAll(tempBaseDir)
    output, err := ioutil.TempFile("", "notary-test-import-")
    require.NoError(t, err)
    defer os.RemoveAll(output.Name())
    k := &keyCommander{
        configGetter: func() (*viper.Viper, error) {
            v := viper.New()
            v.SetDefault("trust_dir", tempBaseDir)
            return v, nil
        },
    }
    k.outFile = output.Name()
    err = output.Close() // close so export can open
    require.NoError(t, err)
    k.exportKeyIDs = []string{"one", "three"}

    b := &pem.Block{}
    b.Bytes = make([]byte, 1000)
    rand.Read(b.Bytes)

    b2 := &pem.Block{}
    b2.Bytes = make([]byte, 1000)
    rand.Read(b2.Bytes)

    c := &pem.Block{}
    c.Bytes = make([]byte, 1000)
    rand.Read(c.Bytes)

    bBytes := pem.EncodeToMemory(b)
    b2Bytes := pem.EncodeToMemory(b2)
    cBytes := pem.EncodeToMemory(c)

    fileStore, err := store.NewPrivateKeyFileStorage(tempBaseDir, notary.KeyExtension)
    require.NoError(t, err)
    err = fileStore.Set("one", bBytes)
    require.NoError(t, err)
    err = fileStore.Set("two", b2Bytes)
    require.NoError(t, err)
    err = fileStore.Set("three", cBytes)
    require.NoError(t, err)

    err = k.exportKeys(&cobra.Command{}, nil)
    require.NoError(t, err)

    outRes, err := ioutil.ReadFile(k.outFile)
    require.NoError(t, err)

    block, rest := pem.Decode(outRes)
    require.Equal(t, b.Bytes, block.Bytes)
    require.Equal(t, "one", block.Headers["path"])

    block, rest = pem.Decode(rest)
    require.Equal(t, c.Bytes, block.Bytes)
    require.Equal(t, "three", block.Headers["path"])
    require.Len(t, rest, 0)
}

开发者ID:jfrazelle,项目名称:notary,代码行数:60,代码来源:keys_test.go

示例4: importPem

// import (decode + decrypt) PEM block which must match one of the given types
func importPem(pemData []byte, prompt PasswordPrompt, types ...string) (*pem.Block, error) {
    block, pemData := pem.Decode(pemData)
    block2, _ := pem.Decode(pemData)
    if nil == block || nil != block2 {
        return nil, NotASinglePemBlock
    }

    {
        // check pem type
        validType := false
        for _, t := range types {
            if t == block.Type {
                validType = true
                break
            }
        }
        if !validType {
            return nil, UnexpectedPemBlock
        }
    }

    if err := utils.DecryptPemBlock(block, prompt); nil != err {
        return nil, err
    }
    return block, nil
}

开发者ID:NeuralSpaz,项目名称:go-acme-client,代码行数:27,代码来源:export.go

示例5: main

func main() {
    random, _ := os.Open("/dev/urandom", os.O_RDONLY, 0)
    pembytes := readEntireFile("/home/kris/SSL/gr0g.crt")
    cert, _ := pem.Decode(pembytes)
    keybytes := readEntireFile("/home/kris/SSL/gr0g.key")
    pk, _ := pem.Decode(keybytes)

    privatekey, _ := x509.ParsePKCS1PrivateKey(pk.Bytes)

    config := new(tls.Config)
    config.Certificates = make([]tls.Certificate, 1)
    config.Certificates[0].Certificate = [][]byte{cert.Bytes}
    config.Certificates[0].PrivateKey = privatekey
    config.Rand = random
    //config.RootCAs = caset
    config.Time = time.Seconds
    listener, err := tls.Listen("tcp", "0.0.0.0:8443", config)

    fmt.Printf("%s\n", err)
    for {
        conn, _ := listener.Accept()
        go func() {
            for {
                buf := make([]byte, 1024)
                _, err := conn.Read(buf)
                if err != nil {
                    return
                }
                fmt.Printf("%s", buf)
            }
        }()
    }
}

开发者ID:gr0gmint,项目名称:gocon,代码行数:33,代码来源:sslserver.go

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