文件与 Base64 相互转换

104 字
1 分钟
文件与 Base64 相互转换
2025-06-30
浏览量 加载中...

文件与 Base64 相互转换#

function ConvertTo-Base64 {
param (
[Parameter(Mandatory=$true)]
[string]$InputFile,
[Parameter(Mandatory=$true)]
[string]$OutputFile
)
# $f=[io.file]::ReadAllBytes($InputFile)
$f = Get-Content -Path $InputFile -Encoding Byte
# $f = Get-Content -Path $InputFile -AsByteStream # PS 7+
$base64 = [Convert]::ToBase64String($f)
Set-Content -Path $OutputFile -Value $base64
# [io.file]::WriteAllText($OutputFile,$base64)
}
function ConvertTo-File {
param (
[Parameter(Mandatory=$true)]
[string]$InputFile,
[Parameter(Mandatory=$true)]
[string]$OutputFile
)
# $f=[io.file]::ReadAllText($InputFile) # [Text.Encoding]::UTF8,[Text.Encoding]::GetEncoding("GB2312")
$f = Get-Content -Path $InputFile
$bytes = [Convert]::FromBase64String($f)
Set-Content -Path $OutputFile -Value $bytes -Encoding Byte
# Set-Content -Path $OutputFile -Value $bytes -AsByteStream # PS 7+
# [io.file]::WriteAllBytes($OutputFile,$bytes)
}
# Usage
# ConvertTo-Base64 -InputFile 'C:\MyFolder\file.exe' -OutputFile 'C:\MyFolder\base64.txt'
# ConvertTo-File -InputFile 'C:\MyFolder\base64.txt' -OutputFile 'C:\MyFolder\file.exe'

文章分享

如果这篇文章对你有帮助,欢迎分享给更多人!

文件与 Base64 相互转换
https://www.satxm.top/posts/base64-file-convert/
作者
Satxm
发布于
2025-06-30
许可协议
CC BY-NC-SA 4.0
最后更新于 2025-06-30,距今已过 250 天

部分内容可能已过时

评论区

Profile Image of the Author
Satxm
Satxm's Book
公告
欢迎来到我的博客!这是一则示例公告。
音乐
封面

音乐

暂未播放

0:00 0:00
暂无歌词
分类
标签
站点统计
文章
48
分类
11
标签
44
总字数
24,574
运行时长
0
最后活动
0 天前

目录