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