/
DSASignatureFormatter.cs
45 lines (35 loc) · 1.32 KB
/
DSASignatureFormatter.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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
namespace System.Security.Cryptography
{
public class DSASignatureFormatter : AsymmetricSignatureFormatter
{
private DSA? _dsaKey;
public DSASignatureFormatter() { }
public DSASignatureFormatter(AsymmetricAlgorithm key) : this()
{
ArgumentNullException.ThrowIfNull(key);
_dsaKey = (DSA)key;
}
public override void SetKey(AsymmetricAlgorithm key)
{
ArgumentNullException.ThrowIfNull(key);
_dsaKey = (DSA)key;
}
public override void SetHashAlgorithm(string strName)
{
if (strName.ToUpperInvariant() != HashAlgorithmNames.SHA1)
{
// To match desktop, throw here
throw new CryptographicUnexpectedOperationException(SR.Cryptography_InvalidOperation);
}
}
public override byte[] CreateSignature(byte[] rgbHash)
{
ArgumentNullException.ThrowIfNull(rgbHash);
if (_dsaKey == null)
throw new CryptographicUnexpectedOperationException(SR.Cryptography_FormatterMissingKey);
return _dsaKey.CreateSignature(rgbHash);
}
}
}