登录
首页 >  Golang >  Go问答

有没有办法对 Go 编译器生成的 Windows 可执行文件进行签名?

来源:stackoverflow

时间:2024-04-06 09:21:35 250浏览 收藏

哈喽!大家好,很高兴又见面了,我是golang学习网的一名作者,今天由我给大家带来一篇《有没有办法对 Go 编译器生成的 Windows 可执行文件进行签名?》,本文主要会讲到等等知识点,希望大家一起学习进步,也欢迎大家关注、点赞、收藏、转发! 下面就一起来看看吧!

问题内容

我试图找出是否有可能对 Go 编译器生成的可执行文件进行签名。我在构建/编译选项中看不到这一点。这可能吗?


解决方案


对可执行文件进行签名不是编译器的责任,但它是构建过程的一部分。将构建脚本更改为在 go 编译器生成 exe 或 dll 文件后运行 signtool.exe。提供私钥文件的路径和密码(如果使用 .pfx 文件),它将为您签名。这与 visual studio 使用的过程相同。

https://learn.microsoft.com/en-us/windows/desktop/seccrypto/signtool

显然,go 的 go build 命令非常简洁:you cannot add additional build steps nor custom commands to go buildnor is there any "hooks" feature for the go command(除了 gogenerate 之外,但当我们想要构建后时,这是一个预构建步骤。步骤)。

...这意味着 you'll need a makefile

这是一个快速而肮脏的 makefile(适用于 windows 上的 gnu make),用于单文件项目 main.go,它应该(未经测试)自动运行构建后的 signtool

# golang makefile based on https://golangdocs.com/makefiles-golang
BINARY_NAME=mygoproject.exe
 
build:
    go build -o ${BINARY_NAME} main.go

    # This runs signtool with a cert in your profile store instead of a *.pfx file, to avoid needing to store a password in the makefile or environment variable: https://stackoverflow.com/questions/26998439/signtool-with-certificate-stored-in-local-computer
    signtool sign /sm /s My /n  /t http://timestamp.digicert.com ${BINARY_NAME}
 
run:
    go build -o ${BINARY_NAME} main.go
    ./${BINARY_NAME}
 
clean:
    go clean
    rm ${BINARY_NAME}

只需从终端运行 make build ,它应该正常工作(我希望如此!)

好了,本文到此结束,带大家了解了《有没有办法对 Go 编译器生成的 Windows 可执行文件进行签名?》,希望本文对你有所帮助!关注golang学习网公众号,给大家分享更多Golang知识!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>