Authenticate Your Data with PKI and Digital Signatures

Authenticate Your Data with PKI and Digital Signatures

ow would you create an application that enables a user to retrieve sensitive data from a database and secure it, preventing other users from tampering with it? The application would have the following feature requirements:

  • The system must require the user to approve the data.
  • The system must store proof that a specific user has read and approved the data.

Timestamps and passwords immediately come to mind, but are they the best solution for such strict data authentication requirements? Because Public Key Infrastructure (PKI) and Digital Signature technology commonly are used in security and privacy software for e-mail, you may not consider them as readily?but you should. PKI and Digital Signatures actually can fulfill the data requirements for your app quite well.

PKI is a framework for message protection and authentication that uses asymmetric encryption. Unlike symmetric encryption algorithms, in which the same key is used to both encrypt and decrypt data, an asymmetric algorithm generates a set of complimentary keys: one for encrypting data and the other for decrypting it. This eliminates the need to share the secret key and also removes the risk of someone intercepting it.

In this article, I will demonstrate how to utilize PKI and Digital Signatures in a sample application that enables users to digitally sign documents, keeping others from modifying them and allowing you to validate user data. The First Step in PKI and Signatures: A Key Pair
To use an asymmetric algorithm you first have to generate a key pair. The first key is the public key, which is published to a key server so it can be shared. The other key is the private key. It is stored locally and kept confidential. To communicate securely with someone, you retrieve the recipient’s public key from a key server and use it to encrypt the data you’re sending. Only a person with knowledge of the private key can decrypt the data. With this scheme, as long as the private key is kept confidential, no one can read a message meant for someone else.

This scheme, however, is not optimal. Asymmetric algorithms are slow. To speed things up, you need to minimize the length of the data that the asymmetric algorithm processes. You can first encrypt the data using a symmetric algorithm and then encrypt the secret key you used using an asymmetric algorithm and the recipient’s public key. This way, only the intended recipient can read the secret key and decrypt the data.

While they can be used for encryption, asymmetric algorithms are manly used in PKIs to generate signatures. Signatures are used to authenticate the origin of a message and to ensure that no one has tampered with the data in the message. Here’s how it works.

When a person is ready to send data, the person:

  1. Generates a digest (a unique string) from the data using a hash algorithm. (Hash algorithms apply mathematical manipulations to the data to extrapolate the digest and are extremely difficult to reverse. Common hash algorithms include SHA-1 and MD5.)
  2. Encrypts the digest using a symmetric algorithm and a randomly generated secret key.
  3. Encrypts the secret key using an asymmetric algorithm and the sender’s private key and appends it to the encrypted digest.
  4. Attaches the signature to the data and sends it off.

To validate the message, the recipient retrieves the sender’s public key from a common key server and reverses the process:

  1. Decrypts the secret key.
  2. Uses it to decrypt the message digest.
  3. Regenerates the digest from the message data.
  4. Compares the regenerated digest and the decrypted one. If they don’t match, the data was either tampered with or it was encrypted by someone other then the sender. Either way the information in the message can be discarded as invalid.

PKI in Your Apps
Now that you have an idea what PKI and Signatures are about, look at a sample application that uses this technology. The following are the application’s requirements:

  • Once the reviewer reads a document, he or she approves it with a signature.
  • Once the document is signed, the document can no longer be modified, and the signature is stored to prove that the reviewer has validated it.
  • The medical or quality assurance fields are logical areas for such an application, where test results need to be reviewed and approved by a specialist and proof needs to be kept for auditing purposes in case something goes wrong.

    Also, for the sample application, I simulate keycard technology using a floppy disk. Keycards are often used in conjunction with a PKI to store a user’s private key information. Such an application requires a user to insert his or her keycard into a card reader and enter a password. The password is used to decrypt the private key information on the card. (If this concept sounds familiar, it should; your bank card uses a similar technology.)

    Here’s how the application works:

    1. The reviewer starts the application and uses the Document>Open menu, which displays a dialog listing the available documents in the database.
    2. The reviewer selects a document from the list and opens it.
    3. After he’s read through it, the reviewer clicks the Sign Document button on the toolbar.
    4. The system requires the reviewer to insert his floppy disk (keycard) in drive A: and input his username and password.
    5. The system validates the username and password against the information in the database.
    6. The system uses the password to decrypt the Private Key data stored on the floppy disk.
    7. The system uses the Private Key data to generate a signature for the document.
    8. The signature is stored in the database, and the document is now considered approved (DocStatus=1).

    You can download the full source code for this application. To better explain how the encryption and signing process works, I’ll drill down on two processes: signing a document and validating a signature.

    Signing a Document Digitally
    So how does one go about signing a document? As I stated earlier, a signature is a way of both making sure that the data in the document has not been tampered with and of authenticating the document as originating from the correct person. The first step in signing the document is to ask the user to insert his keycard (a floppy disk for the sample application) and then to prompt him for his username and password. The password is validated against the data contained in the database. It then is used to decrypt the private key information on the floppy disk (see Listing 1).

    With the private key data retrieved, you can generate a signature for the document. Luckily, the RSA provider exposes a method for signing data, so you don’t need to bother with the intermediary steps. You can go right to generating the signature.

    When dealing with the .NET framework’s Cryptography functions, all your strings have to be converted to and from byte arrays. Do this with the ByteArrayToSting() and StringTobyteArray() functions provided in the sample code. The following snippet shows how to use these functions:

    'Initialize the RSA providerobjRSAProvider = New RSACryptoServiceProvider()'load up the stored private key dataobjRSAProvider.FromXmlString(strPrivateKeyData)'Generate the signaturearSignature = objRSAProvider.SignData(arDocText, "MD5")'Convert the signature to a string '(So we can easily store it)strSignature = ByteArrayToString(arSignature)

    The hash algorithm is specified as a parameter when calling the SignData() method. In the sample application, you use the MD5 algorithm to generate the digest. To complete the operation, the generated signature is inserted into the database and the status of the document is changed to approved (DocStatus=1)Validating a Signature
    To validate the signature, reverse the procedure:

    1. Decrypt the secret key using the reviewer’s Public Key data.
    2. Decrypt the stored digest using the secret key.
    3. Regenerate the digest value from the saved document.
    4. Validate the digest by comparing the two values.

    If the digest strings are identical, then the data was not compromised and you can prove?with reasonable certainty?that the reviewer did indeed read and approve the data.

    To make this work, retrieve the Pubic Key of the user who signed that data. (The user’s identity is stored in the Document table in the DocReviewer field. The user’s Public Key information is then retrieved from the KeyData field of the User table.) Here again the RSA provider has a function to help you:

    'Validate the signature using 'the Reviewer's public key dataobjRSAProvider = New RSACryptoServiceProvider()objRSAProvider.FromXmlString(strPublicKeyData)arStoredSignature = StringToByteArray(strSignature)If  objRSAProvider.VerifyData(arDocText, "MD5", _   arStoredSignature) Then  MsgBox("Document is valid!", _         MsgBoxStyle.Exclamation, "Valid")Else  MsgBox("Document is NOT valid!", _         MsgBoxStyle.Critical, "Not Valid")End If

    The VerifyData() function accepts the data, algorithm name, and signature value and returns a Boolean indicating success or failure.

    Use What You’ve Learned
    Now that you have gained a better understanding of Public Key Infrastructures and Digital Signatures, you can use them in real-life applications. Of course, commercial applications use a more complicated and robust approach in their PKI implementations. If you’re interested in learning more about cryptography and PKI, a good place to start is the RSA Labs Web site. It contains several documents explaining how the keys and signatures are generated.

    devx-admin

    devx-admin

    Share the Post:
    Poland Energy Future

    Westinghouse Builds Polish Power Plant

    Westinghouse Electric Company and Bechtel have come together to establish a formal partnership in order to design and construct Poland’s inaugural nuclear power plant at

    EV Labor Market

    EV Industry Hurting For Skilled Labor

    The United Auto Workers strike has highlighted the anticipated change towards a future dominated by electric vehicles (EVs), a shift which numerous people think will

    Soaring EV Quotas

    Soaring EV Quotas Spark Battle Against Time

    Automakers are still expected to meet stringent electric vehicle (EV) sales quotas, despite the delayed ban on new petrol and diesel cars. Starting January 2023,

    Affordable Electric Revolution

    Tesla Rivals Make Bold Moves

    Tesla, a name synonymous with EVs, has consistently been at the forefront of the automotive industry’s electric revolution. The products that Elon Musk has developed

    Poland Energy Future

    Westinghouse Builds Polish Power Plant

    Westinghouse Electric Company and Bechtel have come together to establish a formal partnership in order to design and construct Poland’s inaugural nuclear power plant at the Lubiatowo-Kopalino site in Pomerania.

    EV Labor Market

    EV Industry Hurting For Skilled Labor

    The United Auto Workers strike has highlighted the anticipated change towards a future dominated by electric vehicles (EVs), a shift which numerous people think will result in job losses. However,

    Soaring EV Quotas

    Soaring EV Quotas Spark Battle Against Time

    Automakers are still expected to meet stringent electric vehicle (EV) sales quotas, despite the delayed ban on new petrol and diesel cars. Starting January 2023, more than one-fifth of automobiles

    Affordable Electric Revolution

    Tesla Rivals Make Bold Moves

    Tesla, a name synonymous with EVs, has consistently been at the forefront of the automotive industry’s electric revolution. The products that Elon Musk has developed are at the forefront because

    Sunsets' Technique

    Inside the Climate Battle: Make Sunsets’ Technique

    On February 12, 2023, Luke Iseman and Andrew Song from the solar geoengineering firm Make Sunsets showcased their technique for injecting sulfur dioxide (SO₂) into the stratosphere as a means

    AI Adherence Prediction

    AI Algorithm Predicts Treatment Adherence

    Swoop, a prominent consumer health data company, has unveiled a cutting-edge algorithm capable of predicting adherence to treatment in people with Multiple Sclerosis (MS) and other health conditions. Utilizing artificial

    Personalized UX

    Here’s Why You Need to Use JavaScript and Cookies

    In today’s increasingly digital world, websites often rely on JavaScript and cookies to provide users with a more seamless and personalized browsing experience. These key components allow websites to display

    Geoengineering Methods

    Scientists Dimming the Sun: It’s a Good Thing

    Scientists at the University of Bern have been exploring geoengineering methods that could potentially slow down the melting of the West Antarctic ice sheet by reducing sunlight exposure. Among these

    why startups succeed

    The Top Reasons Why Startups Succeed

    Everyone hears the stories. Apple was started in a garage. Musk slept in a rented office space while he was creating PayPal with his brother. Facebook was coded by a

    Bold Evolution

    Intel’s Bold Comeback

    Intel, a leading figure in the semiconductor industry, has underperformed in the stock market over the past five years, with shares dropping by 4% as opposed to the 176% return

    Semiconductor market

    Semiconductor Slump: Rebound on the Horizon

    In recent years, the semiconductor sector has faced a slump due to decreasing PC and smartphone sales, especially in 2022 and 2023. Nonetheless, as 2024 approaches, the industry seems to

    Elevated Content Deals

    Elevate Your Content Creation with Amazing Deals

    The latest Tech Deals cater to creators of different levels and budgets, featuring a variety of computer accessories and tools designed specifically for content creation. Enhance your technological setup with

    Learn Web Security

    An Easy Way to Learn Web Security

    The Web Security Academy has recently introduced new educational courses designed to offer a comprehensible and straightforward journey through the intricate realm of web security. These carefully designed learning courses

    Military Drones Revolution

    Military Drones: New Mobile Command Centers

    The Air Force Special Operations Command (AFSOC) is currently working on a pioneering project that aims to transform MQ-9 Reaper drones into mobile command centers to better manage smaller unmanned

    Tech Partnership

    US and Vietnam: The Next Tech Leaders?

    The US and Vietnam have entered into a series of multi-billion-dollar business deals, marking a significant leap forward in their cooperation in vital sectors like artificial intelligence (AI), semiconductors, and

    Huge Savings

    Score Massive Savings on Portable Gaming

    This week in tech bargains, a well-known firm has considerably reduced the price of its portable gaming device, cutting costs by as much as 20 percent, which matches the lowest

    Cloudfare Protection

    Unbreakable: Cloudflare One Data Protection Suite

    Recently, Cloudflare introduced its One Data Protection Suite, an extensive collection of sophisticated security tools designed to protect data in various environments, including web, private, and SaaS applications. The suite

    Drone Revolution

    Cool Drone Tech Unveiled at London Event

    At the DSEI defense event in London, Israeli defense firms exhibited cutting-edge drone technology featuring vertical-takeoff-and-landing (VTOL) abilities while launching two innovative systems that have already been acquired by clients.

    2D Semiconductor Revolution

    Disrupting Electronics with 2D Semiconductors

    The rapid development in electronic devices has created an increasing demand for advanced semiconductors. While silicon has traditionally been the go-to material for such applications, it suffers from certain limitations.

    Cisco Growth

    Cisco Cuts Jobs To Optimize Growth

    Tech giant Cisco Systems Inc. recently unveiled plans to reduce its workforce in two Californian cities, with the goal of optimizing the company’s cost structure. The company has decided to

    FAA Authorization

    FAA Approves Drone Deliveries

    In a significant development for the US drone industry, drone delivery company Zipline has gained Federal Aviation Administration (FAA) authorization, permitting them to operate drones beyond the visual line of

    Mortgage Rate Challenges

    Prop-Tech Firms Face Mortgage Rate Challenges

    The surge in mortgage rates and a subsequent decrease in home buying have presented challenges for prop-tech firms like Divvy Homes, a rent-to-own start-up company. With a previous valuation of

    Lighthouse Updates

    Microsoft 365 Lighthouse: Powerful Updates

    Microsoft has introduced a new update to Microsoft 365 Lighthouse, which includes support for alerts and notifications. This update is designed to give Managed Service Providers (MSPs) increased control and

    Website Lock

    Mysterious Website Blockage Sparks Concern

    Recently, visitors of a well-known resource website encountered a message blocking their access, resulting in disappointment and frustration among its users. While the reason for this limitation remains uncertain, specialists