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

报告相同问题?

悬赏问题

  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改