Add migrated to .NET 8.0 variant of Hcs.Client

This commit is contained in:
2025-09-26 19:48:32 +09:00
parent da127df8f6
commit 6cd2fb82e9
503 changed files with 223796 additions and 0 deletions

View File

@ -0,0 +1,72 @@
using GostCryptography.Properties;
using System;
using System.Security.Cryptography;
namespace GostCryptography.Base
{
/// <summary>
/// Класс вычисления цифровой подписи ГОСТ
/// </summary>
public class GostSignatureFormatter : AsymmetricSignatureFormatter
{
/// <summary>
/// Конструктор
/// </summary>
public GostSignatureFormatter()
{
}
/// <summary>
/// Конструктор
/// </summary>
/// <param name="privateKey">Закрытый ключ для вычисления цифровой подписи</param>
/// <exception cref="ArgumentOutOfRangeException"></exception>
/// <exception cref="ArgumentNullException"></exception>
public GostSignatureFormatter(AsymmetricAlgorithm privateKey) : this()
{
SetKey(privateKey);
}
private GostAsymmetricAlgorithm _privateKey;
/// <inheritdoc />
public override void SetKey(AsymmetricAlgorithm privateKey)
{
if (privateKey == null)
{
throw ExceptionUtility.ArgumentNull(nameof(privateKey));
}
if (!(privateKey is GostAsymmetricAlgorithm gostPrivateKey))
{
if (privateKey.SignatureAlgorithm.IndexOf("gost", StringComparison.OrdinalIgnoreCase) < 0)
{
throw ExceptionUtility.ArgumentOutOfRange(nameof(privateKey), Resources.ShouldSupportGost3410);
}
gostPrivateKey = new GostExternalAsymmetricAlgorithm(privateKey);
}
_privateKey = gostPrivateKey;
}
/// <inheritdoc />
public override void SetHashAlgorithm(string hashAlgorithmName)
{
}
/// <inheritdoc />
public override byte[] CreateSignature(byte[] hash)
{
if (hash == null)
{
throw ExceptionUtility.ArgumentNull(nameof(hash));
}
var reverseSignature = _privateKey.CreateSignature(hash);
Array.Reverse(reverseSignature);
return reverseSignature;
}
}
}