-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
DSAOther.cs
58 lines (46 loc) · 1.79 KB
/
DSAOther.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
52
53
54
55
56
57
58
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.IO;
namespace System.Security.Cryptography.X509Certificates.Tests
{
internal class DSAOther : DSA
{
private readonly DSA _impl;
internal DSAOther()
{
_impl = DSA.Create(1024);
}
public override byte[] CreateSignature(byte[] rgbHash) => _impl.CreateSignature(rgbHash);
public override void ImportParameters(DSAParameters parameters) => _impl.ImportParameters(parameters);
public override DSAParameters ExportParameters(bool includePrivateParameters) =>
_impl.ExportParameters(includePrivateParameters);
public override bool VerifySignature(byte[] rgbHash, byte[] rgbSignature) =>
_impl.VerifySignature(rgbHash, rgbSignature);
protected override byte[] HashData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm)
{
if (hashAlgorithm != HashAlgorithmName.SHA1)
throw new NotSupportedException();
using (HashAlgorithm alg = SHA1.Create())
{
return alg.ComputeHash(data, offset, count);
}
}
protected override byte[] HashData(Stream data, HashAlgorithmName hashAlgorithm)
{
if (hashAlgorithm != HashAlgorithmName.SHA1)
throw new NotSupportedException();
using (HashAlgorithm alg = SHA1.Create())
{
return alg.ComputeHash(data);
}
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
_impl.Dispose();
}
base.Dispose(disposing);
}
}
}