Summary of the new feature/enhancement
Hi,
Request a native cmdlet for getting a hash value (MD5, SHA256, etc) of an inputted string.
eg - something like Get-FileHash ... but not file based
justification. I've seen requirements for such a thing around the place, but with incorrectly implemented (hopefully the below isn't too far off) and sub optimal solutions. eg bad code from SE and write to disk, hash from disk with Get-FileHash
Proposed technical implementation details (optional)
something like the following maybe
function Get-StringHash {
[CmdletBinding()]
[OutputType([System.String])]
param (
[ValidateScript({ ![System.String]::IsNullOrEmpty($PSItem) })][System.String]$inputString,
[ValidateSet('MD5', 'SHA1', 'SHA256', 'SHA384', 'SHA512')][System.String]$hashAlgo
)
process {
$ErrorActionPreference = 'stop'
Set-StrictMode -Version 'latest'
$inputBytes = [System.Text.Encoding]::UTF8.GetBytes($inputString)
$hashAlgorithm = [System.Security.Cryptography.HashAlgorithm]::Create($hashAlgo)
# [System.Security.Cryptography.HashAlgorithmName]
return ( [System.BitConverter]::ToString( $hashAlgorithm.ComputeHash($inputBytes) ) -replace '-' )
}
}
Summary of the new feature/enhancement
Hi,
Request a native cmdlet for getting a hash value (MD5, SHA256, etc) of an inputted string.
eg - something like Get-FileHash ... but not file based
justification. I've seen requirements for such a thing around the place, but with incorrectly implemented (hopefully the below isn't too far off) and sub optimal solutions. eg bad code from SE and write to disk, hash from disk with Get-FileHash
Proposed technical implementation details (optional)
something like the following maybe