Add project
Basic formatting applied. Unnecessary comments have been removed. Suspicious code is covered by TODO.
This commit is contained in:
70
Hcs.Client/ClientApi/HcsClient.cs
Normal file
70
Hcs.Client/ClientApi/HcsClient.cs
Normal file
@ -0,0 +1,70 @@
|
||||
using GostCryptography.Gost_R3411;
|
||||
using Hcs.ClientApi.DebtRequestsApi;
|
||||
using Hcs.ClientApi.DeviceMeteringApi;
|
||||
using Hcs.ClientApi.FileStoreServiceApi;
|
||||
using Hcs.ClientApi.HouseManagementApi;
|
||||
using Hcs.ClientApi.OrgRegistryCommonApi;
|
||||
using Hcs.ClientApi.RemoteCaller;
|
||||
using System;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
|
||||
namespace Hcs.ClientApi
|
||||
{
|
||||
/// <summary>
|
||||
/// Единый клиент для вызова всех реализованных функций интеграции с ГИС ЖКХ
|
||||
/// </summary>
|
||||
public class HcsClient : HcsClientConfig
|
||||
{
|
||||
public HcsClient()
|
||||
{
|
||||
HcsServicePointConfig.InitConfig();
|
||||
|
||||
// TODO: Вынести в конфиг
|
||||
// Роль поставщика информации по умолчанию
|
||||
Role = HcsOrganizationRoles.RSO;
|
||||
}
|
||||
|
||||
public void SetSigningCertificate(X509Certificate2 cert, string pin = null)
|
||||
{
|
||||
if (cert == null) throw new ArgumentNullException("Не указан сертификат для подписания данных");
|
||||
if (pin == null) pin = HcsConstants.DefaultCertificatePin;
|
||||
|
||||
Certificate = cert;
|
||||
CertificateThumbprint = cert.Thumbprint;
|
||||
CertificatePassword = pin;
|
||||
CryptoProviderType = cert.GetProviderType();
|
||||
}
|
||||
|
||||
public HcsDebtRequestsApi DebtRequests => new HcsDebtRequestsApi(this);
|
||||
public HcsHouseManagementApi HouseManagement => new HcsHouseManagementApi(this);
|
||||
public HcsOrgRegistryCommonApi OrgRegistryCommon => new HcsOrgRegistryCommonApi(this);
|
||||
public HcsFileStoreServiceApi FileStoreService => new HcsFileStoreServiceApi(this);
|
||||
public HcsDeviceMeteringApi DeviceMeteringService => new HcsDeviceMeteringApi(this);
|
||||
|
||||
public X509Certificate2 FindCertificate(Func<X509Certificate2, bool> predicate)
|
||||
{
|
||||
return HcsCertificateHelper.FindCertificate(predicate);
|
||||
}
|
||||
|
||||
public X509Certificate2 ShowCertificateUI()
|
||||
{
|
||||
return HcsCertificateHelper.ShowCertificateUI();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Производит для потока хэш по алгоритму "ГОСТ Р 34.11-94" в строке binhex
|
||||
/// </summary>
|
||||
public string ComputeGost94Hash(System.IO.Stream stream)
|
||||
{
|
||||
// API HouseManagement указывает, что файлы приложенные к договору должны размещаться
|
||||
// с AttachmentHASH по стандарту ГОСТ. Оказывается, ГИСЖКХ требует применения устаревшего
|
||||
// алгоритма ГОСТ Р 34.11-94 (соответствует `rhash --gost94-cryptopro file` в linux).
|
||||
using var algorithm = new Gost_R3411_94_HashAlgorithm(GostCryptoProviderType);
|
||||
var savedPosition = stream.Position;
|
||||
stream.Position = 0;
|
||||
var hashValue = HcsUtil.ConvertToHexString(algorithm.ComputeHash(stream));
|
||||
stream.Position = savedPosition;
|
||||
return hashValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user