private static string GetRequestSignature(TechnicalUser user, string requestId, DateTime timestamp, string additionalSignatureData = null) { var formattedTimestamp = timestamp.ToString("yyyyMMddHHmmss"); var signatureData = $"{requestId}{formattedTimestamp}{user.SigningKey.Value}{additionalSignatureData}"; return(Sha512.GetSha3Hash(signatureData)); }
private static Dto.ManageInvoiceRequest CreateManageInvoicesRequest <T>( TechnicalUser user, SoftwareIdentification software, ExchangeToken token, Dto.ManageInvoiceOperationType operation, ISequence <T> invoices, Func <T, Dto.InvoiceData> invoiceDataGetter) { var operations = invoices.Values.Select(item => { var invoiceData = invoiceDataGetter(item.Value); var invoiceDataBytes = Encoding.UTF8.GetBytes(XmlManipulator.Serialize(invoiceData)); return(new Dto.InvoiceOperationType { index = item.Index, invoiceData = invoiceDataBytes, invoiceOperation = operation, electronicInvoiceHash = invoiceData.completenessIndicator.Match( t => new Dto.CryptoType { cryptoType = RequestEncryptionAlgorithm, Value = Sha512.GetSha3Hash(Convert.ToBase64String(invoiceDataBytes)) }, f => null ) }); }); var invoiceHashes = operations.Select(t => Sha512.GetSha3Hash($"{t.invoiceOperation}{Convert.ToBase64String(t.invoiceData)}")); var invoiceSignatureData = string.Join("", invoiceHashes); var request = CreateRequest <Dto.ManageInvoiceRequest>(user, software, invoiceSignatureData); request.exchangeToken = Encoding.UTF8.GetString(token.Value); request.invoiceOperations = new Dto.InvoiceOperationListType { compressedContent = false, invoiceOperation = operations.ToArray() }; return(request); }
private static Dto.ManageInvoiceRequest CreateManageInvoicesRequest <T>(TechnicalUser user, SoftwareIdentification software, ExchangeToken token, Dto.ManageInvoiceOperationType operation, ISequentialEnumerable <T> invoices, Func <T, Dto.InvoiceData> mapper) { var operations = invoices.Select(item => new Dto.InvoiceOperationType { index = item.Index, invoiceData = Encoding.UTF8.GetBytes(XmlManipulator.Serialize(mapper(item.Item))), invoiceOperation = operation }); var invoiceHashes = operations.Select(t => Sha512.GetSha3Hash($"{t.invoiceOperation}{Convert.ToBase64String(t.invoiceData)}")); var invoiceSignatureData = string.Join("", invoiceHashes); var request = CreateRequest <Dto.ManageInvoiceRequest>(user, software, invoiceSignatureData); request.exchangeToken = Encoding.UTF8.GetString(token.Value); request.invoiceOperations = new Dto.InvoiceOperationListType { compressedContent = false, invoiceOperation = operations.ToArray() }; return(request); }