Ejemplo n.º 1
0
        public async Task <bool> VerifyUploadedFile(Guid guid)
        {
            var file = await _filesRepository.GetFileAsync(guid);

            if (file == null)
            {
                return(false);
            }

            var stream = await _blobStorage.DownloadFile(file.Name);

            if (stream == null)
            {
                return(false);
            }

            var md5                     = MD5.Create();
            var blobHashValue           = Convert.ToBase64String(md5.ComputeHash(stream));
            var blockchainFileHashValue = await _ethereumStorage.GetDocumentHashFromChain(file.Guid.ToString());

            var isValid = blobHashValue == blockchainFileHashValue;

            var entry = new BlockchainHistory
            {
                FileGuid  = file.Guid,
                Timestamp = DateTime.Now,
                Status    = isValid ? BlockchainStatuses.Verified : BlockchainStatuses.Corrupted
            };

            await _filesRepository.SaveAsync(entry);

            return(true);
        }
Ejemplo n.º 2
0
        public async Task SaveAsync(BlockchainHistory history)
        {
            await _context.AddAsync(history);

            await SaveChangesAsync();
        }