首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >powershell中base64解码的替代方案

powershell中base64解码的替代方案
EN

Stack Overflow用户
提问于 2022-01-14 12:44:39
回答 2查看 1.1K关注 0票数 2

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

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

我遇到了一个问题'base64‘,其中DB正在试图连接和存储密码。因为PowerShell没有意识到。我想知道是否有人知道我怎样才能修复这个问题,并且仍然使用windows或其他方法,使我能够继续使用指南的其余部分?

错误代码:

代码语言:javascript
运行
复制
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错误消息

EN

回答 2

Stack Overflow用户

发布于 2022-01-14 12:56:36

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

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

代码语言:javascript
运行
复制
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 7文本和base64之间转换的插入替代:

代码语言:javascript
运行
复制
PS ~> 'Hello, World!' |base64 --encode
SGVsbG8sIFdvcmxkIQ==
PS ~> 'Hello, World!' |base64 --encode |base64 --decode
Hello, World!

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

代码语言:javascript
运行
复制
PS ~> . .\path\to\base64.ps1

上面的工作也将从一个脚本。如果您有一个多行的粘贴感知外壳( PSReadLine的默认控制台主机应该可以),也可以直接将函数定义粘贴到提示符中:)

票数 5
EN

Stack Overflow用户

发布于 2022-01-14 16:46:36

您正在尝试在Windows上执行命令行,这些命令行是为类似Unix的平台编写的,这两个命令行的内容如下:

  • 他们所期望的外部实用程序(base64)
  • 它们使用的shell语法(export POSTGRES_PASSWORD=$(...);为与POSIX兼容的shell(如bash)编写的)。

Mathias的有用答案向您展示了如何在PowerShell中模拟base64实用程序,您甚至可以通过额外的、非平凡的工作来模拟export shell命令,但并不是所有情况都可以这样处理,例如使用\"来转义"字符的命令行(这将破坏PowerShell的语法,尝试echo "3\" of snow.")。

因此,我建议在可行的情况下通过WSL运行命令,或者花时间将命令行转换为PowerShell--本机等效的命令行。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70710764

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档