/// <summary> /// Validate the hmac from a received message /// </summary> /// <param name="receivedHmac"></param> /// <param name="decryptedSaleToPoiMessageByteArray"></param> /// <param name="encryptionDerivedKey"></param> private void ValidateHmac(byte[] receivedHmac, byte[] decryptedSaleToPoiMessageByteArray, EncryptionDerivedKey encryptionDerivedKey) { var hmacSha256Wrapper = new HmacSha256Wrapper(); byte[] hmac = hmacSha256Wrapper.HMac(decryptedSaleToPoiMessageByteArray, encryptionDerivedKey.HmacKey); bool isValid = true; if (receivedHmac.Length == hmac.Length) { for (int i = 0; i < hmac.Length; i++) { if (receivedHmac[i] != hmac[i]) { isValid = false; } } } else { isValid = false; } if (!isValid) { throw new NexoCryptoException("Hmac validation failed"); } }
public SaleToPoiMessageSecuredEncryptor() { _encryptionDerivedKeyGenerator = new EncryptionDerivedKeyGenerator(); _aesEncryptor = new AesEncryptor(); _hmacSha256Wrapper = new HmacSha256Wrapper(); _ivModGenerator = new IvModGenerator(); }