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条)

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置