-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Closed
Labels
Issue-Enhancementthe issue is more of a feature request than a bugthe issue is more of a feature request than a bugResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility modulecmdlets in the Microsoft.PowerShell.Utility module
Description
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 '-' )
}
}
Metadata
Metadata
Assignees
Labels
Issue-Enhancementthe issue is more of a feature request than a bugthe issue is more of a feature request than a bugResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility modulecmdlets in the Microsoft.PowerShell.Utility module