chapter four

4 Message integrity and authentication

 

This chapter covers

  • Guaranteeing data integrity using the Secure Hash Algorithm
  • Ensuring sender authenticity with a hash-based message authentication code (HMAC)
  • Ensuring data integrity using an HMAC
  • Using the Java Cryptography Architecture and Java Cryptography Extensions

This chapter is the first step in a friendly introduction to cryptographic algorithms for application developers. We won’t cover the mathematics behind these algorithms. Instead, we’ll demonstrate cryptography concepts with working Java examples so you can build the intuition and background you need to understand application security.

Cryptographic algorithms are the foundational security building blocks, no matter what programming language you write code in or which cloud provider you deploy your application on. These documentation and mysterious error messages from security libraries make perfect sense if you understand the basics of cryptography. You’ll no longer get stuck or blindly copy and paste from Stack Overflow and blog posts.

4.1 The goals of cryptography

4.2 Cryptographic hash functions

4.2.1 Secure Hash Algorithm

4.2.2 Verifying integrity using a cryptographic hash function

4.2.3 Design for hash function change

4.2.4 Exercises

4.3 Java Cryptography Architecture and Java Cryptology Extensions

4.4 Implementing message integrity in Java

4.5 Message authentication code

4.5.1 Hashed message authentication code

4.5.2 Java support for HMAC

4.5.3 Exercises

4.6 Guaranteeing authenticity using HMAC

4.7 Exercise answers

Summary