public async Task <byte[]> TransformData(byte[] originalData) { string hash; using (var stream = new MemoryStream(originalData)) { hash = await this.Hasher.ComputeHash(stream); } var hashBytes = Encoding.UTF8.GetBytes(hash); var dataWithSignature = new DataWithSignature(originalData, hashBytes); return(dataWithSignature.AsByteArray()); }
public async Task <IDecryptionResult> GetOriginalData(byte[] transformedData) { var dataWithSignature = DataWithSignature.FromByteArray(transformedData); var expectedHash = Encoding.UTF8.GetString(dataWithSignature.Signature); using (var stream = new MemoryStream(dataWithSignature.Data)) { var actualHash = await this.Hasher.ComputeHash(stream); if (expectedHash != actualHash) { return(new FailedDecryptionResult()); } } return(new SuccessfulDecryptionResult(dataWithSignature.Data)); }