public void Process(BaseSecureModel source, BaseHashModel destination) { var ptrPsw = Marshal.SecureStringToGlobalAllocAnsi(source.SecurePassword); destination.Hash = _hashAlgorithm.GetHash($"{source.Login}|{Marshal.PtrToStringAnsi(ptrPsw)}"); Marshal.ZeroFreeGlobalAllocAnsi(ptrPsw); }
public async Task <DocumentMetadata> SaveDocumentAsync(Document document) { // save the content if it doesn't already exist string documentHash = _hashAlgorithm.GetHash(document.Content); bool duplicate = await _blobContainer.ExistsAsync(documentHash); if (duplicate) { _eventSource.OnDuplicateFoundInDocumentStore(document.Id, documentHash); } else { // compress the document byte[] compressedContent = _compressor.Compress(document.Content); await _blobContainer.SetAsync(documentHash, compressedContent); } // save the metadata, in reverse chronological order string documentMetadataId = string.Format( CultureInfo.InvariantCulture, "{0}-{1}", DateTimeOffset.UtcNow.GetDescendingOrderString(), Guid.NewGuid()); var documentMetadata = new DocumentMetadata { Id = documentMetadataId, DocumentId = document.Id, Hash = documentHash, Duplicate = duplicate, Created = DateTimeOffset.UtcNow }; await _table.SetAsync(GetDocumentMetadataPartitionKey(document.Id), documentMetadataId, documentMetadata); return(documentMetadata); }
private string GetQueryByEventPartitionKey(EventId eventId) { string raw = string.Format( CultureInfo.InvariantCulture, "{0}-{1}-{2}", eventId.Type, eventId.ProviderId, eventId.ResourceId); string hash = _hashAlgorithm.GetHash(Encoding.UTF8.GetBytes(raw)); return(string.Format( CultureInfo.InvariantCulture, "{0}-{1}", "event", hash)); }