Wed, Jun
4 New Articles

A Practical Look at Digital Signatures in Java

  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Whether it's verifying the integrity of a message's source, a software license file, or a download, employing digital signatures is imperative.


So just what is a digital signature anyway?


A digital signature is the digital era's equivalent of yesterday's hand-written signature. That is, each time we sign that receipt after using our debit or credit card, we are effectively telling our financial institution that we agreed to pay a given price for a given item. In the event that an alleged fraudulent charge is made, authorities can perform signature comparisons to help determine the validity of the claim. Digital signatures work in a similar fashion for electronic messages. That is, they use a form of asymmetric algorithms whereby the message's sender applies a digital signing algorithm to the message using a private key (asymmetric algorithms use public- and private-key technology in which each user has a private key that is known only to the user and a public key that is publicly known). The output is referred to as the digital signature. When the message is received by its target recipient, the sender's authenticity is determined by using a signature verification algorithm coupled with the sender's public key. Through the employment of this scheme, digital signatures offer two very important benefits to their users:


  • Integrity: The message's recipient can confidently assume that the message, as constructed by the sender, has not been altered in any manner during transmission.
  • Authentication: The message's recipient can confidently assume that the source of the message is as it appears. That is, it would be extremely difficult for an attacker to spoof the identity of the message's source.


It's because of these benefits that digital signatures are so widely used today, especially given the nature of activities for which society uses its computers (e.g., online shopping, online banking, etc.). Without the use of digital signatures, it would be trivial for an attacker to forge a message or alter the contents of a message, actions that are just not acceptable by today's standards.

Why Are Digital Signatures Important?

It shouldn't be difficult to see why employing digital signatures is imperative in today's world. For example, imagine that we send instructions to a financial institution to transfer a large sum of money into another account. We'd definitely hope there's some sort of digital signature accompanying that transfer request! Or imagine sending emails within our organization; in the absence of digitally signing our emails (which most email clients now support), it would be (relatively) easy for an attacker to forge emails on our behalf.


While digital signatures play an integral role in today's digital security, there are some disguised drawbacks. For example, what happens if a party's private key is inadvertently compromised? In essence, that would allow an attacker to forge the party's signature. This also leads to problems in the area of repudiation. In this context, "repudiation" refers to the act of disclaiming responsibility for a message. That is, a signer states that he or she did not sign the message, but the recipient claims that the message was verified. If signers make such claims, they're repudiating their signature key. In a nutshell, it's of utmost importance that private keys are kept private. In the event of any suspected compromise of that key, the owner of the key should immediately inform potential recipients of the compromise and then generate a new pair of keys.

Digital Signatures in Java

Because Java is widely used for many enterprise-level applications, it should come as no surprise that it supports a wide spectrum of cryptographic capabilities, one of which just happens to be out-of-the-box JDK support for digital signatures. Java supports the notion of a SignedObject, which is an authentic runtime object whose integrity cannot be compromised without being detected. This special object contains a serializable object (i.e., the to-be-signed object) and its signature. The signed object is a deep copy, a "clone" of sorts of the original to-be-signed object. It must be a deep copy for integrity's sake; manipulation of the original object has no effect on the copy.


Related Java Classes

There are a wide variety of objects with which we might work when performing digital signature-type operations in Java. The following paragraphs will make a brief attempt to summarize some of the commonly used objects (note that all objects mentioned exist within the java.security package) and explain how they might be used.


  • KeyPairGenerator: As the name suggests, this is the object that's responsible for algorithm-specific key generation. It allows us to also specify the key length; typically, longer key lengths lead to harder-to-break digital signatures. The output of this object is a KeyPair.
  • KeyPair: This is the output from a KeyPairGenerator for a specific algorithm. It contains two accessor methods to retrieve both the public and private keys.
  • Key: The Key interface is the top-level interface for all keys, namely PrivateKey and PublicKey. Every key is tied to a specific algorithm (e.g., DSA or RSA) and has an encoding format (e.g., X.509) for representation outside of the JVM.
  • PrivateKey: This is a special Key implementation, most notably used for type safety (e.g., we wouldn't want to accidentally use a PublicKey where a PrivateKey was expected). This key should be kept secret to the party performing the digital signature. Failure to keep this key private will provide a malicious user with the ability to forge the user's signature.
  • PublicKey: Like PrivateKey, PublicKey is a special Key used primarily for type safety. This key should be made publicly known; users will use this key, coupled with the appropriate verification algorithm, to determine the validity of a digital signature.
  • Signature: Based on a user-specified signing algorithm, this is the "engine" that actually performs the signing and verification of digital signatures.
  • SignedObject: Per the JDK specifications, a SignedObject is used for creating runtime authentic objects whose integrity cannot be compromised without being detected. A signed object is created by effectively coupling a serializable object (i.e., the user object to digitally sign) with a PrivateKey and a Signature (i.e., the two objects used to create the digital signature). This object can also be serialized and deserialized for object persistence.

As you can see, there are many pieces involved when working with digital signatures in Java, ranging from key generation to digital signature verification. Each piece plays an instrumental role in the end-to-end process, so it's important to study each component.


Another item worth touching on is the notion of cryptographic providers. As we study many of the classes encompassed by the java.security package, we will encounter many instances in which their methods accept a provider parameter. This parameter refers to whose implementation of the various algorithms is used. For example, both Company A and Company B might provide implementations of the DSA algorithm; this allows us to choose whose implementation to select.


Example: Digitally Signing a License File

A common instance in which a digital signature is used is in the area of software-license file generation and verification. Often, software vendors will use a (vendor-generated) license file of sorts to determine, at runtime, the features available to the customer. At the very least, the license verifier engine should be able to detect when the license file has been changed from its original state (e.g., a mischievous customer tries to alter the license file so that features they didn't pay for are available). The following steps outline the procedure to create a license file (it's assumed that the software features are stored in an instance of java.util.Properties, although any serializable object would suffice):


  1. Using KeyPairGenerator, generate a public- and private-key pair and serialize them for future use. Be sure to store the private key in a "secure" area of the file system (this step needs to be performed only once across all license file generation).
  2. Deserialize the PrivateKey generated as part of step 1.
  3. Construct an instance of java.util.Properties such that its key-value pairs represent feature-enabled Booleans.
  4. Construct an instance of SignedObject (this object represents the license in its entirety), passing the Properties instance, the PrivateKey instance, and a Signature instance. The algorithm used for the signature should pair with the algorithm used to generate the keys (e.g., if "DSA" was used to generate the keys, then "SHA/DSA" should be used for the signature).
  5. Serialize the SignedObject instance and transmit it, along with the PublicKey generated in step 1, to the customer. Any future modification to the signed object will be detected by the (forthcoming) verification steps.

Note: Although it's less flexible, the PublicKey could also be hard-coded (e.g., as a hexadecimal sequence) into the application. And since it's (by definition) in the public domain, we're not concerned with anyone decompiling the application and looking for private information.


Now that we've seen how to generate and transmit a signed license file, let's take a look at how we can verify its integrity before using it.


  1. Deserialize the PublicKey as generated in the previous set of steps; this key is an integral part in verifying the contents of the license file.
  2. Deserialize the SignedObject as generated in the previous set of steps; this is the object whose integrity we want to verify (e.g., to ensure that the customer hasn't tried to alter the license).
  3. Invoke signedObject.verify(publicKey, signature) and ensure the value true is returned; if not (or if exceptions occur), the license file's integrity has been compromised and processing should not continue.

Take Note

As with any programming project, there are always traps to look for while coding. One such trap in Java is the signing engine's provider. As mentioned previously, most of the APIs that have been referenced will also accept a provider (e.g., SUN, IBM, etc.) argument, specifying which vendor's implementation of the signing engine to use. For example, a malicious implementation of the SignedObject::verify(...) method could always return true, tricking a program into thinking the signature was verified. As such, this is definitely something worth keeping your eyes open for (i.e., always use a trusted provider).

Get Digitized

Digital signatures serve a wide array of purposes in today's world of computing. Whether it's verifying the integrity of a message's source, a software license file, or a download, employing digital signatures is imperative. They provide effective solutions to the previously mentioned common problems. A wide variety of programming language libraries provide digital-signature support, and as we've seen from the Java pseudo-examples, their use is relatively simple when compared with their added benefits.

Joe Cropper is a Software Engineer at IBM in Rochester, Minnesota. He works as part of the Cloud Systems Software Development organization, focusing on virtualization and cloud management solutions. Joe has held a number of roles in other organizations as well, ranging from IBM i and Electronic Support. His areas of expertise include virtualization and cloud management, OpenStack, Java EE, and multi-tiered applications. Joe can be reached via email at This email address is being protected from spambots. You need JavaScript enabled to view it..



Support MC Press Online

$0.00 Raised:

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: