public CryptoHashProcessor(JObject settingObject)
        {
            EnsureArg.IsNotNull(settingObject, nameof(settingObject));

            var settingFactory    = new AnonymizerSettingsFactory();
            var cryptoHashSetting = settingFactory.CreateAnonymizerSetting <CryptoHashSetting>(settingObject);

            _cryptoHashFunction = new CryptoHashFunction(cryptoHashSetting);
        }
        public void Process(DicomDataset dicomDataset, DicomItem item, Dictionary <string, object> settings = null)
        {
            var encoding = Encoding.UTF8;

            if (item is DicomMultiStringElement)
            {
                var encryptedValues = ((DicomMultiStringElement)item).Get <string[]>().Select(GetCryptoHashString);
                dicomDataset.AddOrUpdate(item.Tag, encryptedValues.ToArray());
            }
            else if (item is DicomStringElement)
            {
                var value          = ((DicomMultiStringElement)item).Get <string>();
                var encryptedValue = GetCryptoHashString(value);
                dicomDataset.AddOrUpdate(item.Tag, encryptedValue);
            }
            else
            {
                var valueBytes     = ((DicomElement)item).Get <byte[]>();
                var encryptesBytes = CryptoHashFunction.ComputeHmacSHA256Hash(valueBytes, _cryptoHashKey);
                dicomDataset.AddOrUpdate(item.Tag, encryptesBytes);
            }
        }
        public string GetCryptoHashString(string input)
        {
            var resultBytes = CryptoHashFunction.ComputeHmacSHA256Hash(Encoding.UTF8.GetBytes(input), _cryptoHashKey);

            return(resultBytes == null ? null : string.Concat(resultBytes.Select(b => b.ToString("x2"))));
        }
        public void GivenAStream_WhenComputeHmac512_CorrectHashShouldBeReturned(Stream input, string expectedHash)
        {
            var hashData = CryptoHashFunction.Hash(input, new HMACSHA512(Encoding.UTF8.GetBytes(TestHashKey)));

            Assert.Equal(expectedHash, hashData == null ? null : string.Concat(hashData.Select(b => b.ToString("x2"))));
        }