You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-Draft/RFC0018-Get-StringHash.md
+93-23Lines changed: 93 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,18 +8,20 @@ Area: Cmdlet
8
8
Comments Due: 3/2/2017
9
9
---
10
10
11
-
# Get-StringHash cmdlet
11
+
# Get-Hash cmdlet
12
12
13
-
Add the new cmdlet to PowerShell to get cryptographically strong hashes for strings.
13
+
Add the new cmdlet to PowerShell to get cryptographically strong hashes for strings, files and file streams.
14
14
15
-
Current .Net implementation of GetHashCode method calculates a hash that is not a global (across application domains) safe and is not a permanent value.
15
+
Currently Powershell only has Get-FileHash cmdlet to get a file hashes.
16
+
The cmdlet enhance and replace `Get-FileHash` cmdlet to support strings. `Get-FileHash` becomes an alias of `Get-Hash`.
17
+
18
+
Current .Net implementation of GetHashCode method calculates a hash for strings that is not a global (across application domains) safe and is not a permanent value.
16
19
According to the documentation, this method has many practical limitations.
>As a result, hash codes should never be used outside of the application domain in which they were created, they should never be used as key fields in a collection, and they should never be persisted.
22
+
>As a result, the hash codes should never be used outside of the application domain in which they were created, they should never be used as key fields in a collection, and they should never be persisted.
20
23
21
-
Currently Powershell only has Get-FileHash cmdlet to get a file hashes.
22
-
Users are forced to use a workaround to get a string hashes:
24
+
Also users are forced to use a workaround to get a string hashes:
All of `InputString`, `Path`, `LiteralPath` parameters has `string` type and we can use `ValueFromPipeline` only for one parameter - `InputString`.
154
+
`Path`, `LiteralPath` parameters is accepted from pipeline by property name.
155
+
(If we want `ValueFromPipeline` for `Path` we should split on `Get-StringHash` and `Get-FileHash`.)
156
+
91
157
### Encoding
92
158
93
-
.Net hash algorithm methods work on byte buffer. So the cmdlet must convert a input string to byte array.
94
-
This process is a encoding sensitive.
95
-
To correctly process the user must specify the encoding of incoming strings.
159
+
.Net hash algorithm methods work on byte buffer.
160
+
161
+
We read files as binary and so no encodings needed.
162
+
163
+
For strings the cmdlet must convert a input string to byte array. This process is a encoding sensitive. To correctly process users must specify the encoding of incoming strings by `Encoding` parameter.
96
164
97
165
### InputString accept null and empty input strings
98
166
@@ -101,10 +169,12 @@ To correctly process the user must specify the encoding of incoming strings.
101
169
.Net hash algorithm methods throw for null input buffer.
102
170
This behavior is not convenient when processing an array of strings by using a pipeline:
103
171
```powershell
104
-
"test1", $null, "test2" | Get-StringHash
172
+
"test1", $null, "test2" | Get-Hash
105
173
```
106
174
Best behavior is to create null as result hash for null string and generate non-terminating error.
107
175
108
176
## Alternate Proposals and Considerations
109
177
110
-
None
178
+
We cosider `Base64` as special encoding and not a hash. It is recomended to implement `Base64` encoding in some `ConvertTo-Base64` and `ConvertFrom-Base64` cmdlets.
179
+
180
+
We could split the `Get-Hash` functionality on `Get-FileHash` and `Get-StringHash` cmdlets or even `Get-FileHash`, `Get-StreamHash` and `Get-StringHash`.
0 commit comments