Skip to Content
Java Security, 2nd Edition
book

Java Security, 2nd Edition

by Scott Oaks
May 2001
Intermediate to advanced
618 pages
20h 50m
English
O'Reilly Media, Inc.
Content preview from Java Security, 2nd Edition

Secure Message Digests

As we stated in Chapter 7, the message digest by itself does not give us a very high level of security. We can tell whether somehow the output file in this example has been corrupted because the text that we read in won’t produce the same message digest that was saved with the file. But there’s nothing to prevent someone from changing both the text and the digest stored in the file in such a way that the new digest reflects the altered text.

A secure message digest is called a Message Authentication Code (MAC). A MAC has the property that it cannot be created solely from the input data; it requires a secret key that is shared by the sender and receiver. Hence, an intermediate party cannot change both the data and the MAC without the receiver detecting that the data has been corrupted.

There are various ways in which a message digest can be made into a MAC, but the core Java security API does not provide any standard techniques for doing so. However, JCE does provide a class to produce a MAC, and there are simple ways to calculate a MAC on your own.

The Mac Class

The Mac class (javax.crypto.Mac) is part of the Java Cryptography Extension because it involves a cryptographic operation: a secret key is used to calculate the message digest. This mean that in order to use the Mac class, both sender and receiver must agree upon which secret key to use. As we discussed in Chapter 10, that means the sender and receiver must have previously exchanged and stored ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Java Security Handbook

Java Security Handbook

Jamie Jaworski, Paul J. Perrone, Venkata S.R. Krishna Chaganti
Java Cryptography

Java Cryptography

Jonathan Knudsen

Publisher Resources

ISBN: 0596001576Errata Page