douhui8454 2018-06-25 01:57
浏览 35
已采纳

将密码从[] byte转换为字符串时,请在wincred软件包中添加空格

I'm using Windows Credential Manager to store database credentials for my application built in Go through the wincred package.

It works for retrieving passwords for credentials created by the package itself, however for credentials created straight through Windows Credential Manager, the package is adding "spaces" (byte '0') between the characters when converting from []byte to string.

//Retrieve a credential object
package main

import (
    "fmt"
    "github.com/danieljoos/wincred"
)

func main() {
    cred, err := wincred.GetGenericCredential("myGoApplication")
    if err == nil {
        fmt.Println(string(cred.CredentialBlob))
    }
} 

In the example above I've set the password for "myGoApplication" as 123456, but it retrieves as

1 2 3 4 5 6

The []byte representation is

[49 0 50 0 51 0 52 0 53 0 54 0]

I'm wondering if anyone has any idea on what might be causing this issue.

  • 写回答

2条回答 默认 最新

  • douchenbiao0916 2018-10-10 04:31
    关注

    As a workaround I'm removing the null bytes which work's for my purposes for the time being but this is unlikely to be the right solution.

    bytes.Replace(myBytes, []byte("\000"), nil, -1)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?