代码之家  ›  专栏  ›  技术社区  ›  BaltoStar

PS SHA512散列文件,输出为base 64编码字符串

  •  0
  • BaltoStar  · 技术社区  · 6 年前

    我需要采取一个文件的SHA512,转换为基64编码字符串,并输出到文件。

    PS > Get-FileHash <path to file> -Algorithm SHA512
    

    我知道这个功能是可用的 [System.Convert]::ToBase64String

    0 回复  |  直到 6 年前
        1
  •  1
  •   boxdog    6 年前

    你可以这样做:

    # Get the hash of the file
    $hash = Get-FileHash <path to input file> -Algorithm SHA512
    
    # Convert hash to byte representation
    $hashBytes = [System.Text.Encoding]::Unicode.GetBytes($hash.Hash)
    
    # Convert bytes to base64, then output to file
    [System.Convert]::ToBase64String($hashBytes) | Out-File <path to hash output file>
    

    # Read encoded string from text file
    $encodedHash = Get-Content <path to hash output file>
    
    # Convert to from base64 to byte representation
    $hashBytes = [System.Convert]::FromBase64String($encodedHash)
    
    # Convert bytes to hash string
    [System.Text.Encoding]::Unicode.GetString($hashBytes)
    

    您可能可以将其中的一些步骤组合起来,但这将为您提供所需步骤的图片

    推荐文章