windows - 通过 Windows 命令行将特定文件编码为 Base64
问题描述
我需要在 Windows 操作系统上使用命令行在屏幕上生成特定文件的 base64 数据(不生成文件)。
我已经看到在 Unix 系统上足以使用
cat <file_name>| base64
获取编码为base64的文件内容。
在 Windows 上,我无法获得相同的结果。
我找到了这个解决方案:
certutil -encode -f <file_name> tmp.b64 && findstr /v /c:- tmp.b64 && del tmp.b64
但这需要系统生成一个临时文件,所以最后去销毁它。仅使用该certutil
命令,屏幕上的结果就会被包含不相关信息的 3 行所污染。
有人可以帮我在 Windows 上提供一个只生成 base64 数据的命令吗?
更新:我通过这个新版本的命令改进了屏幕上的结果:
certutil -encode -f <file_name> tmp.b64 && cls && findstr /v /c:- tmp.b64 && del tmp.b64
结果更像我的要求,但我想避免tmp.b64
每次都创建临时文件。
解决方案
我建议在你的 Windows 机器上安装OpenSSL 。设置 PATH 变量后,它很容易:
type <file_name> | openssl base64
推荐阅读
- vbscript - 我可以在 if 语句中添加条件吗
- blockchain - 如何在私有网络的底层区块链中设置系统属性?
- elasticsearch - 当我在弹性搜索中使用翻转时,我是写入别名还是索引?
- javascript - 浮动按钮和“弯曲”导航栏
- javascript - 谷歌表格脚本提交按钮不起作用
- bash - 需要创建一个循环菜单shell脚本,不知道如何让它循环
- python - Pandas 在索引和值范围之间选择数据
- python - 如何将一列文本转换为 n-gram 到 one-hot 编码?
- google-bigquery - 如何将日期数据类型从字符串更改为日期
- c++ - OpenGL透明纹理重叠/混合问题