Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

get-filehash

Usando a Função GET-filehash eu tive um resultado diferente do mesmo script, é normal?

function Get-SHA256 {
    param (
        $Filename
    )
    $Conteudo = Get-Content $Filename
    $filebyte = [System.Text.Encoding]::UTF8.GetBytes($Conteudo)

    $sha256 = New-Object System.Security.Cryptography.SHA256Managed
    $hash256 =  $sha256.ComputeHash($filebyte)
    $fullex = New-Object System.Text.StringBuilder
    foreach ($byte in $hash256) {
        $hex = $byte.ToString("X2")
        $fullex.Append($hex) > $null
    }
    $fullex.ToString()
}

$arquivo = "C:\temp\Scripts\hs-fuctions.ps1"
$hashDoArquivo = Get-SHA256 $arquivo

Write-host "O hash do arquivo $arquivo eh $hashDoArquivo" -BackgroundColor Red -ForegroundColor Yellow

saida PS C:\Temp\Scripts> c:\Temp\Scripts\get-SHA256.ps1 O hash do arquivo C:\temp\Scripts\hs-fuctions.ps1 eh E4096D0ED9C845671AB4E88CBD372A57D639D5AA9FA63FB657679CCC9C54C455

get-filehash PS C:\Temp\Scripts> Get-FileHash .\hs-fuctions.ps1

Algorithm Hash Path


SHA256 EE9B9FFFC6171C89C8941B612B5388855590DD144BF6B623EE32F782CBAD7373 C:\Temp\Scripts\hs-fuctions.ps1

1 resposta
solução!

Oi Rodrigo tudo bem?

Um espaçozinho a mais irá mudar todo o hash, os arquivos tem que estar exatamente iguais. As vezes a codificação do arquivo (UFT-8, ou ANSI, ou outros) pode estar fazendo que o hash saia diferente.

Espero ter ajudado!!!

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software