param( [Parameter(Mandatory = $true, Position = 0)] [string]$File, [Parameter(Mandatory = $false, Position = 1)] [ValidateSet("MD5", "SHA1", "SHA256", "SHA384", "SHA512")] [string]$Algorithm = "SHA384" ) if (-not (Test-Path -LiteralPath $File -PathType Leaf)) { Write-Host "ERROR: File tidak ditemukan: $File" -ForegroundColor Red exit 1 } $manifestNames = @{ "MD5" = "MD5" "SHA1" = "SHA-1" "SHA256" = "SHA-256" "SHA384" = "SHA-384" "SHA512" = "SHA-512" } try { $resolvedPath = (Resolve-Path -LiteralPath $File).Path # Hitung hash $result = Get-FileHash -LiteralPath $resolvedPath -Algorithm $Algorithm $hex = $result.Hash # Convert HEX menjadi raw bytes. # Kompatibel dengan Windows PowerShell 5.1 dan PowerShell 7+ [byte[]]$bytes = for ($i = 0; $i -lt $hex.Length; $i += 2) { [Convert]::ToByte($hex.Substring($i, 2), 16) } # Raw hash bytes -> Base64 $base64 = [Convert]::ToBase64String($bytes) $manifestAlgorithm = $manifestNames[$Algorithm] Write-Host "" Write-Host "File : " -NoNewline -ForegroundColor DarkGray Write-Host $resolvedPath Write-Host "Algorithm : " -NoNewline -ForegroundColor DarkGray Write-Host $manifestAlgorithm Write-Host "" Write-Host "HEX" -ForegroundColor Cyan Write-Host $hex Write-Host "" Write-Host "Base64" -ForegroundColor Green Write-Host $base64 #Write-Host "" #Write-Host "MANIFEST.MF" -ForegroundColor Yellow #Write-Host "${manifestAlgorithm}-Digest: $base64" Write-Host "" } catch { Write-Host "ERROR: $($_.Exception.Message)" -ForegroundColor Red exit 1 }