| | | 1 | | using System.Security.Cryptography; |
| | | 2 | | using Renci.SshNet.Common; |
| | | 3 | | |
| | | 4 | | namespace Renci.SshNet.Security.Cryptography |
| | | 5 | | { |
| | | 6 | | /// <summary> |
| | | 7 | | /// Computes a Hash-based Message Authentication Code (HMAC) by using the <see cref="SHA512"/> hash function. |
| | | 8 | | /// </summary> |
| | | 9 | | public class HMACSHA512 : System.Security.Cryptography.HMACSHA512 |
| | | 10 | | { |
| | | 11 | | private readonly int _hashSize; |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// Initializes a new instance of the <see cref="HMACSHA512"/> class with the specified key. |
| | | 15 | | /// </summary> |
| | | 16 | | /// <param name="key">The key.</param> |
| | | 17 | | public HMACSHA512(byte[] key) |
| | 0 | 18 | | : base(key) |
| | 0 | 19 | | { |
| | | 20 | | #pragma warning disable MA0056 // Do not call overridable members in constructor |
| | 0 | 21 | | _hashSize = base.HashSize; |
| | | 22 | | #pragma warning restore MA0056 // Do not call overridable members in constructor |
| | 0 | 23 | | } |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// Initializes a new instance of the <see cref="HMACSHA512"/> class with the specified key |
| | | 27 | | /// and size of the computed hash code. |
| | | 28 | | /// </summary> |
| | | 29 | | /// <param name="key">The key.</param> |
| | | 30 | | /// <param name="hashSize">The size, in bits, of the computed hash code.</param> |
| | | 31 | | public HMACSHA512(byte[] key, int hashSize) |
| | 0 | 32 | | : base(key) |
| | 0 | 33 | | { |
| | 0 | 34 | | _hashSize = hashSize; |
| | 0 | 35 | | } |
| | | 36 | | |
| | | 37 | | /// <summary> |
| | | 38 | | /// Gets the size, in bits, of the computed hash code. |
| | | 39 | | /// </summary> |
| | | 40 | | /// <value> |
| | | 41 | | /// The size, in bits, of the computed hash code. |
| | | 42 | | /// </value> |
| | | 43 | | public override int HashSize |
| | | 44 | | { |
| | 0 | 45 | | get { return _hashSize; } |
| | | 46 | | } |
| | | 47 | | |
| | | 48 | | /// <summary> |
| | | 49 | | /// Finalizes the hash computation after the last data is processed by the cryptographic stream object. |
| | | 50 | | /// </summary> |
| | | 51 | | /// <returns> |
| | | 52 | | /// The computed hash code. |
| | | 53 | | /// </returns> |
| | | 54 | | protected override byte[] HashFinal() |
| | 0 | 55 | | { |
| | 0 | 56 | | var hash = base.HashFinal(); |
| | 0 | 57 | | return hash.Take(HashSize / 8); |
| | 0 | 58 | | } |
| | | 59 | | } |
| | | 60 | | } |