/
KeyedHashAlgorithm.cs
51 lines (43 loc) · 1.74 KB
/
KeyedHashAlgorithm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Diagnostics.CodeAnalysis;
using Internal.Cryptography;
namespace System.Security.Cryptography
{
public abstract class KeyedHashAlgorithm : HashAlgorithm
{
protected KeyedHashAlgorithm() { }
[Obsolete(Obsoletions.DefaultCryptoAlgorithmsMessage, DiagnosticId = Obsoletions.DefaultCryptoAlgorithmsDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
public static new KeyedHashAlgorithm Create() =>
throw new PlatformNotSupportedException(SR.Cryptography_DefaultAlgorithm_NotSupported);
[Obsolete(Obsoletions.CryptoStringFactoryMessage, DiagnosticId = Obsoletions.CryptoStringFactoryDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
[RequiresUnreferencedCode(CryptoConfigForwarder.CreateFromNameUnreferencedCodeMessage)]
public static new KeyedHashAlgorithm? Create(string algName) =>
CryptoConfigForwarder.CreateFromName<KeyedHashAlgorithm>(algName);
public virtual byte[] Key
{
get
{
return KeyValue.CloneByteArray();
}
set
{
KeyValue = value.CloneByteArray();
}
}
protected override void Dispose(bool disposing)
{
// For keyed hash algorithms, we always want to zero out the key value
if (disposing)
{
if (KeyValue != null)
{
Array.Clear(KeyValue);
}
KeyValue = null!;
}
base.Dispose(disposing);
}
protected byte[] KeyValue = null!;
}
}