gpt4 book ai didi

windows - 在 powershell 中替代 base64 解码

转载 作者:行者123 更新时间:2023-12-01 23:06:53 24 4
gpt4 key购买 nike

我按照指南将数据库连接到 kubernetes: https://itnext.io/basic-postgres-database-in-kubernetes-23c7834d91ef

在 Windows 10 64 位上安装 Kubernetes (minikube) 后: https://minikube.sigs.k8s.io/docs/start/

我在数据库尝试连接和存储密码时遇到“base64”问题。由于 PowerShell 无法识别它。我想知道是否有人有任何想法可以解决此问题并仍然使用 Windows 或其他方法使我能够继续本指南的其余部分?

错误代码:

base64 : The term 'base64' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:131
+ ... postgresql -o jsonpath="{.data.postgresql-password}" | base64 --decod ...
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (base64:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

export : The term 'export' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ export POSTGRES_PASSWORD=$(kubectl get secret --namespace default pos ...
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (export:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

Windows Powershell Error message

最佳答案

Mac OS 和一些 *nix 发行版中的 base64 cli 在 Windows 上不可用。

可以编写一个名为base64 的小函数来模仿base64 unix 工具的行为:

function base64 {
# enumerate all pipeline input
$input |ForEach-Object {
if($MyInvocation.UnboundArguments -contains '--decode'){
# caller supplied `--decode`, so decode
$bytes = [convert]::FromBase64String($_)
[System.Text.Encoding]::ASCII.GetString($bytes)
} else {
# default mode, encode ascii text as base64
$bytes = [System.Text.Encoding]::ASCII.GetBytes($_)
[convert]::ToBase64String($bytes)
}
}
}

这应该可以替代 ASCII/UTF7 文本和 base64 之间的转换:

PS ~> 'Hello, World!' |base64 --encode
SGVsbG8sIFdvcmxkIQ==
PS ~> 'Hello, World!' |base64 --encode |base64 --decode
Hello, World!

要与您现有的脚本一起使用,在执行其他脚本之前,在您的 shell 中使用函数定义简单点源脚本:

PS ~> . .\path\to\base64.ps1

以上内容也适用于脚本。如果你有一个多行粘贴感知 shell(Windows 的默认控制台主机和 PSReadLine 应该没问题),你也可以直接将函数定义粘贴到提示符中:)

关于windows - 在 powershell 中替代 base64 解码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70710764/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com