powershell - 比较 Azure Properties.ContentMD5 和 Get-Filehash 之间的字符串输出
问题描述
解决方案
ContentMD5
is a base64 representation of the binary hash value, not the resulting hex string :)
$md5sum = [convert]::FromBase64String('Z78raj5mVwVLS4bhN6Ejgg==')
$hdhash = [BitConverter]::ToString($md5sum).Replace('-','')
Here we convert base64 -> binary -> hexadecimal
If you need to do it the other way around (ie. for obtaining a local file hash, then using that to search for blobs in Azure), you'll first need to split the hexadecimal string into byte-size chunks, then convert the resulting byte array to base64:
$hdhash = '67BF2B6A3E6657054B4B86E137A12382'
$bytes = [byte[]]::new($hdhash.Length / 2)
for($i = 0; $i -lt $bytes.Length; $i++){
$offset = $i * 2
$bytes[$i] = [convert]::ToByte($hdhash.Substring($offset,2), 16)
}
$md5sum = [convert]::ToBase64String($bytes)
推荐阅读
- opencv - 计算图像的时刻
- javascript - 用于提取双引号和非引号字符串Javascript的正则表达式模式
- c++ - 编译器不应该能够从概念中推断出模板参数吗?
- python - 打印字符串的中间字符时出错
- python-3.x - 如何在 Python 中使用 selenium 提取并将表数据解析为 DataFrame Pandas
- javascript - 如何将 y 轴国家标签向左对齐?
- lazy-loading - 将 Microsoft Teams 聊天导出到文件以进行归档
- python - 在我的情况下如何忽略 KeyError?(Python)
- omnet++ - 如何将跟踪文件导入 OMNeT++/Veins?
- excel - 将 Excel 格式的日期转换为 Stata