@@ -122,6 +122,22 @@ public static byte[] Sha256(this byte[] value)
122
122
#endif
123
123
}
124
124
125
+ /// <summary>
126
+ /// Computes the hash value for the specified byte array using the sha512 algorithm.
127
+ /// </summary>
128
+ /// <param name="value">The input to compute the hash code for.</param>
129
+ /// <returns>The computed hash code.</returns>
130
+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
131
+ public static byte [ ] Sha512 ( this byte [ ] value )
132
+ {
133
+ #if ! NET5_0_OR_GREATER
134
+ using var sha512 = SHA512 . Create ( ) ;
135
+ return sha512 . ComputeHash ( value ) ;
136
+ #else
137
+ return SHA512 . HashData ( value ) ;
138
+ #endif
139
+ }
140
+
125
141
/// <summary>
126
142
/// Computes the hash value for the specified region of the specified byte array using the sha256 algorithm.
127
143
/// </summary>
@@ -140,6 +156,24 @@ public static byte[] Sha256(this byte[] value, int offset, int count)
140
156
#endif
141
157
}
142
158
159
+ /// <summary>
160
+ /// Computes the hash value for the specified region of the specified byte array using the sha512 algorithm.
161
+ /// </summary>
162
+ /// <param name="value">The input to compute the hash code for.</param>
163
+ /// <param name="offset">The offset into the byte array from which to begin using data.</param>
164
+ /// <param name="count">The number of bytes in the array to use as data.</param>
165
+ /// <returns>The computed hash code.</returns>
166
+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
167
+ public static byte [ ] Sha512 ( this byte [ ] value , int offset , int count )
168
+ {
169
+ #if ! NET5_0_OR_GREATER
170
+ using var sha512 = SHA512 . Create ( ) ;
171
+ return sha512 . ComputeHash ( value , offset , count ) ;
172
+ #else
173
+ return SHA512 . HashData ( value . AsSpan ( offset , count ) ) ;
174
+ #endif
175
+ }
176
+
143
177
/// <summary>
144
178
/// Computes the hash value for the specified byte array using the sha256 algorithm.
145
179
/// </summary>
@@ -148,7 +182,7 @@ public static byte[] Sha256(this byte[] value, int offset, int count)
148
182
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
149
183
public static byte [ ] Sha256 ( this ReadOnlySpan < byte > value )
150
184
{
151
- byte [ ] buffer = new byte [ 32 ] ;
185
+ var buffer = new byte [ 32 ] ;
152
186
#if ! NET5_0_OR_GREATER
153
187
using var sha256 = SHA256 . Create ( ) ;
154
188
sha256 . TryComputeHash ( value , buffer , out _ ) ;
@@ -158,6 +192,24 @@ public static byte[] Sha256(this ReadOnlySpan<byte> value)
158
192
return buffer ;
159
193
}
160
194
195
+ /// <summary>
196
+ /// Computes the hash value for the specified byte array using the sha512 algorithm.
197
+ /// </summary>
198
+ /// <param name="value">The input to compute the hash code for.</param>
199
+ /// <returns>The computed hash code.</returns>
200
+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
201
+ public static byte [ ] Sha512 ( this ReadOnlySpan < byte > value )
202
+ {
203
+ var buffer = new byte [ 64 ] ;
204
+ #if ! NET5_0_OR_GREATER
205
+ using var sha512 = SHA512 . Create ( ) ;
206
+ sha512 . TryComputeHash ( value , buffer , out _ ) ;
207
+ #else
208
+ SHA512 . HashData ( value , buffer ) ;
209
+ #endif
210
+ return buffer ;
211
+ }
212
+
161
213
/// <summary>
162
214
/// Computes the hash value for the specified byte array using the sha256 algorithm.
163
215
/// </summary>
@@ -168,6 +220,16 @@ public static byte[] Sha256(this Span<byte> value)
168
220
return Sha256 ( ( ReadOnlySpan < byte > ) value ) ;
169
221
}
170
222
223
+ /// <summary>
224
+ /// Computes the hash value for the specified byte array using the sha512 algorithm.
225
+ /// </summary>
226
+ /// <param name="value">The input to compute the hash code for.</param>
227
+ /// <returns>The computed hash code.</returns>
228
+ public static byte [ ] Sha512 ( this Span < byte > value )
229
+ {
230
+ return Sha512 ( ( ReadOnlySpan < byte > ) value ) ;
231
+ }
232
+
171
233
/// <summary>
172
234
/// Computes the hash value for the specified byte array using the keccak256 algorithm.
173
235
/// </summary>
0 commit comments