How to get an MD5 checksum in PowerShell

后端 未结 17 1618
夕颜
夕颜 2020-11-28 01:14

I would like to calculate an MD5 checksum of some content. How do I do this in PowerShell?

17条回答
  •  庸人自扰
    2020-11-28 01:28

    Here is the snippet that I am using to get the MD5 for a given string:

    $text = "text goes here..."
    $md5  = [Security.Cryptography.MD5CryptoServiceProvider]::new()
    $utf8 = [Text.UTF8Encoding]::UTF8
    $bytes= $md5.ComputeHash($utf8.GetBytes($text))
    $hash = [string]::Concat($bytes.foreach{$_.ToString("x2")}) 
    

提交回复
热议问题