md5计算(32位)
$txt="hello world"$md5=New-Object System.Security.Cryptography.MD5CryptoServiceProvider
$bytes=::Default.GetBytes($txt)
$hash=$md5.ComputeHash($bytes)
-join($hash|ForEach-Object{$_.ToString("x2")})
演示效果,以及与在线MD5计算器计算结果比较
自己计算结果:
PS D:\wpp> ./func2.ps1
5eb63bbbe01eeed093cb22bb8f5acdc3
在线工具计算结果
PS D:\wpp> 5eb63bbbe01eeed093cb22bb8f5acdc3 函数包裹:
function getmd5{
param (
$txt
)
$md5=New-Object System.Security.Cryptography.MD5CryptoServiceProvider
$bytes=::Default.GetBytes($txt)
$hash=$md5.ComputeHash($bytes)
-join($hash|ForEach-Object{$_.ToString("x2")})
}
echo (getmd5("hello world")) 6
页:
[1]