3 Common Encryption Mistakes That Are Easy to Avoid - Ubiq (2024)

At Ubiq Security we focus on data security and making it easier for developers to incorporate encryption into their applications. As part of ourwork,we spend time on Slack, Stack Overflow, Reddit, etc. and we seeseveralcommon mistakes that can cause security vulnerabilities that areeasyto resolve. While we don’t think any developer wants to make an insecure product, it is easy to understand how developers not experienced in data security might not realize the impact of grabbing some sample code from the Internet and incorporating it into their application. I often say that writing programs incorporating encryption or data security is not like other software development. Just because an application runs, doesn’t mean you are done or that your application is secure.

Common Encryption Mistake #1 – Inadvertently reducing the range of a hashed value

I have lost count of how many times I have seen someone use sha256 thinking they are creating a256-bitvalue stored in 32 bytes whentheyareactually creatinga 128-bit value stored in 32 bytes.

Look at code snippet below.

KEY = sha256(<some-value>).hex.substr(0,32)

Since the snippet begins with sha256, the developer’s intent appears to be to create a 256-bit key stored in the 32 bytes. However, this code snippet is literally taking a256-bitvalue and reducing it to only 128 bits.

You may have already identified the problem, but let’s walk through it.

  • sha256 produces a 32 byte value with each byte having 256 unique values, meaning 25632 possible (which is the same as 2256).
  • The next step in the code is encoding the results of the hash into hexadecimal which returns a string of 64 characters, with each character having 16 unique values: a hex character [0-9a-f]. This means the string contains 1664 possible values (which is the same as 25632) so we haven’t lost any precision yet.
  • The issue is the substr(0,32) which takes only the first 32 hex characters in the string, meaning that KEY only has 1632 possible values (which is the same as 2128).

Potential Impact:Simply put, the impact is probably catastrophic. Instead of deriving a 256-bit value, the result is only 128 bits. The following article explains the difference between128 and 256 bit encryption keysbut for simple reference, the difference between 128- and 256-bit valuesisroughly a factor of the number 3 followed by 38 zeros.

Solution: Besides more thorough and good code reviews?Don’t think of keys or hashes as a string of characters. Think of them for what they are, an array of bytes. If you need to debug, print, display, or transmit the value, only convert to the necessary form at that time.

Using python as an example:

Incorrect

Correct

key = hashlib.sha256(b"<somevalue>").digest()# debug codeprint(key.hex())

Common Encryption Mistake #2 – Using a hash rather than HMAC

This one is a little more subtle, especially to those who are new to using cryptographic algorithms. Look at the code snippet below.

signature = sha256(Key + Message)

The forum topics and related code indicate an intent to create a signatureas a way toverify message authentication and integrity. Unfortunately, most of the common hashing algorithms such as SHA256 are vulnerable to alength extension attackwhich, simply stated, means:

Hash(Key + Message) can be used to deriveHash(Key + Message + extra) even if the secret Key value is not known.

Potential Impact:The impact of this attack means that the receiver cannot detect if the message has been altered. An attacker can intercept a message and signature, modify the message, derive a new signature, and forward the modified message and signature to the receiver; and the modification would not be detectable.

Not all hash functions are subject to a length extension attack, but unfortunately, the ones that are include SHA256 and many of the other common hash functions.

Solution: Use the right function – HMAC

HMAC –This standsforHash-basedMessageAuthenticationCode which is used to prove message authenticity and that the message hasn’t been altered between a sender and receiver. Fortunately, the HMAC function is explicitlydesignedto produce a signature and is not susceptible to alength extension attack, regardless of the hashing algorithm.

A HMAC typically has three inputs, aKey, aMessage, and ahashing algorithm. The key and message are combined and processed with the hashing algorithm to produce the message signature. If the Key value is secret, it is pretty much impossible to alter the message or signature without detection.

Using python as an example:

Incorrect

signature = hashlib.sha256(Key + Message)

Correct

signature = hmac.new(Key, Message, hashlib.sha256)

Common Encryption Mistake #3 – Inadvertently allowing Hash data collisions

Let’s face it, one of the great features of a good secure hashing algorithm is being collision resistant.This means that there is an extremely unlikely chance that two different inputs will produce the same hashed output.However,hashing algorithms are deterministic,meaning that for the same input, they will alwaysproducethe sameoutput.

Consider this code snippet:

hash(<customer-name> + <customer-ids>)

On the surface, this looks fine, the customer supplies their name, and maybe we force all customers in the DB to be unique. The customer-id is a database sequencer and is guaranteed to be unique, so the developer may be making an incorrect assumption that there is a high likelihood that the result of the hash should be unique. Unfortunately, because the customer provides input to one of these values, they control one of the hash inputs and therefore can have some control over the output and potentially induce hash collisions. Remember thatall ofthe following statements produce identicalresults even thoughthe customer-name and customer-id are unique values.

hashlib.sha256(b"acme-tech" + b"1234").digest()hashlib.sha256(b"acme-tech1" + b"234").digest()hashlib.sha256(b"acme-tech123" + b"4").digest()

Potential Impact:We should all remember that we live in a world where an attacker’s goal is not always to get your data. Sometimes they just want to disrupt your business or prevent you from accessing your own data. If a data collision causes your system to break and they can induce this condition, then they have succeeded. Don’t make it easier for them.

Solution:The developers need to be very careful when hashing values where the user has any direct control over even one part of the hash input. Simplyreplacingthecustomername with a UUID stored in the DB would solve this issue. The UUID may beknownby the customer,but since it isn’t under their control the risk of attacker influenced hash collision would be avoided.

Incorrect

value = hashlib.sha256(customer-name + customer-id)

Correct

value = hashlib.sha256(customer-uuid + customer-id)

Although this article focuses onsome common encryption mistakes and their relatively simple solutions, it easily could have listed many more that are much less obvious or more difficult to resolve. You may start to get an appreciation of how even a slight mistake or oversight can introduce data security vulnerabilities into your application. The Ubiq Platformis designed to avoid the complexity and mistakes that are related to data encryption.Ubiq constantly monitors the latest research related tocryptographicalgorithms,including encryption and hashing,andany newly discoveredvulnerabilities, and it incorporates the newest information into the platform, ensuringyourdata remains as secure as possible.

To see the Ubiq Platform in action, check outthisdemo.

As an expert in data security and encryption, I've spent extensive time researching and implementing secure practices. My experience spans various platforms, including active involvement in communities like Slack, Stack Overflow, and Reddit. Through these engagements, I've encountered and addressed numerous common mistakes that developers make, resulting in potential security vulnerabilities.

The first notable error, as outlined in the provided article, is the inadvertent reduction of the hashed value range. Many developers mistakenly assume that using SHA-256 guarantees a 256-bit value when, in reality, improper coding reduces it to a 128-bit value. The potential impact of such a mistake is catastrophic, significantly weakening the encryption key. The solution involves treating keys or hashes as arrays of bytes and only converting them to a string when necessary.

The second common mistake involves using a hash instead of HMAC (Hash-based Message Authentication Code). The article rightly points out that some hashing algorithms, including SHA-256, are vulnerable to length extension attacks. This can compromise message integrity, allowing an attacker to modify messages without detection. The recommended solution is to use HMAC, which is specifically designed to provide message authenticity and is not susceptible to length extension attacks.

The third mistake discussed is inadvertently allowing hash data collisions. While secure hashing algorithms are designed to be collision-resistant, deterministic behavior makes them susceptible to intentional collisions when users have control over input values. The suggested solution involves careful handling of hash inputs, particularly when users can influence them, by replacing user-controlled values with non-user-controlled ones, such as UUIDs.

In summary, these common encryption mistakes highlight the need for developers to have a deep understanding of cryptographic principles. The provided solutions emphasize the importance of using the right cryptographic functions, handling hash values as arrays of bytes, and avoiding assumptions about input uniqueness. The article underscores the complexity of data security in application development and emphasizes the role of platforms like Ubiq in mitigating such mistakes by incorporating the latest cryptographic research and addressing vulnerabilities.

3 Common Encryption Mistakes That Are Easy to Avoid - Ubiq (2024)

FAQs

What is the easiest encryption method? ›

For example, Electronic Code Book (ECB) mode is the simplest mode of operation. With ECB, each block is encrypted completely independently. The downside of this is that blocks with the same plaintext produce the same ciphertext.

What is poor encryption? ›

Weak encryption algorithms are cryptographic algorithms that provide inadequate security against attacks. Here are some examples of weak encryption algorithms: DES (Data Encryption Standard): is a symmetric key algorithm that uses a 56-bit key.

Is SHA-256 vulnerable? ›

SHA-256 is secure due to its 256-bit hash output, making it exponentially more complex and harder to crack than SHA-1. This complexity helps secure against brute force attacks and collision vulnerabilities, making it a more secure hashing algorithm.

What are the three 3 different encryption methods? ›

There are different types of encryption techniques, but the following three are the most common and widely used: Symmetric Encryption, Asymmetric Encryption, and Hashing.

What is the simplest encryption technique? ›

The Caesar Cipher is one of the simplest and oldest methods of encrypting messages, named after Julius Caesar, who reportedly used it to protect his military communications. This technique involves shifting the letters of the alphabet by a fixed number of places.

How can encryption fail? ›

Weak key generation is one such scenario that can lead to failure. If encryption keys are generated using weak algorithms or predictable patterns, it becomes easier for attackers to guess or break the key, compromising the security of the system. Algorithmic flaws are another potential scenario for failure.

What are the weaknesses of encryption? ›

Cons of Encryption

Encryption requires advanced hardware and software to be implemented, and this can be expensive. Furthermore, encryption hardware and software are often complicated and may require outside consultation or expertise to properly utilize, resulting in additional costs for businesses.

Why is encryption not enough? ›

Once you are logged into your computer, your files are visible not only to you but also the software on your computer. Viruses are software, and can access your data on your encrypted hard drive. Even if you've got antivirus protection on your computer, you are still vulnerable.

Why is SHA-1 no longer secure? ›

In 2005, researchers demonstrated a collision attack against SHA1 that showed it was possible to create two distinct input messages that produced the same hash value. As a result, SHA1 was officially declared insecure by the National Institute of Standards and Technology (NIST) in 2011.

Why is SHA-256 not good for passwords? ›

SHA-256 is the successor of SHA-1, a widely popular algorithm in the past. However, it has since been deemed insecure due to vulnerabilities discovered in its code.

Why can't hash be reversed? ›

A hash cannot be reversed back to the original data because it is a one-way operation. Hashing is commonly used to verify the integrity of data, commonly referred to as a checksum. If two pieces of identical data are hashed using the same hash function, the resulting hash will be identical.

What is the simplest form of encryption? ›

Symmetric encryption

Symmetric algorithms are the simplest and most used form of encryption. Symmetric encryption algorithms are available in two forms: Block algorithms: Encrypt a group of plain text symbols as one block. Stream algorithms: Convert one symbol of plain text directly into ciphertext.

What is the weakest encryption method? ›

Out of these listed symmetric encryption methods, the weakest symmetric encryption method would be DES, or Data Encryption Standard.

What is the most common encryption method? ›

The Advanced Encryption Standard (AES) is the trusted standard algorithm used by the United States government, as well as other organizations. Although extremely efficient in the 128-bit form, AES also uses 192- and 256-bit keys for very demanding encryption purposes.

What is the most simple cryptography? ›

In cryptography, a Caesar cipher, also known as Caesar's cipher, the shift cipher, Caesar's code, or Caesar shift, is one of the simplest and most widely known encryption techniques.

Top Articles
3 High-Yield Dividend Stocks You Can Buy With Less Than $100 Right Now | The Motley Fool
Eight Signs You May Have a Scarcity Money Mindset
Lengua With A Tilde Crossword
It's Official: Sabrina Carpenter's Bangs Are Taking Over TikTok
123 Movies Black Adam
Ds Cuts Saugus
Brgeneral Patient Portal
Kostenlose Games: Die besten Free to play Spiele 2024 - Update mit einem legendären Shooter
Acbl Homeport
414-290-5379
What Does Dwb Mean In Instagram
Brutál jó vegán torta! – Kókusz-málna-csoki trió
3472542504
Restaurants Near Paramount Theater Cedar Rapids
Belle Delphine Boobs
Top tips for getting around Buenos Aires
Nwi Arrests Lake County
Foodland Weekly Ad Waxahachie Tx
Ostateillustrated Com Message Boards
Patrick Bateman Notebook
Committees Of Correspondence | Encyclopedia.com
Wal-Mart 140 Supercenter Products
Missed Connections Dayton Ohio
Testberichte zu E-Bikes & Fahrrädern von PROPHETE.
Touchless Car Wash Schaumburg
Best Nail Salons Open Near Me
Silky Jet Water Flosser
897 W Valley Blvd
*!Good Night (2024) 𝙵ull𝙼ovie Downl𝚘ad Fr𝚎e 1080𝚙, 720𝚙, 480𝚙 H𝙳 HI𝙽DI Dub𝚋ed Fil𝙼yz𝚒lla Isaidub
Elanco Rebates.com 2022
Warn Notice Va
Napa Autocare Locator
Lowell Car Accident Lawyer Kiley Law Group
Chattanooga Booking Report
Texas Baseball Officially Releases 2023 Schedule
Log in or sign up to view
AP Microeconomics Score Calculator for 2023
Ishow Speed Dick Leak
SOC 100 ONL Syllabus
State Legislatures Icivics Answer Key
Spn-523318
Craigslist Free Manhattan
Fwpd Activity Log
Weather Underground Cedar Rapids
Joey Gentile Lpsg
Does Target Have Slime Lickers
Jane Powell, MGM musical star of 'Seven Brides for Seven Brothers,' 'Royal Wedding,' dead at 92
Diario Las Americas Rentas Hialeah
Phunextra
The Missile Is Eepy Origin
Vt Craiglist
Latest Posts
Article information

Author: Laurine Ryan

Last Updated:

Views: 6544

Rating: 4.7 / 5 (57 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Laurine Ryan

Birthday: 1994-12-23

Address: Suite 751 871 Lissette Throughway, West Kittie, NH 41603

Phone: +2366831109631

Job: Sales Producer

Hobby: Creative writing, Motor sports, Do it yourself, Skateboarding, Coffee roasting, Calligraphy, Stand-up comedy

Introduction: My name is Laurine Ryan, I am a adorable, fair, graceful, spotless, gorgeous, homely, cooperative person who loves writing and wants to share my knowledge and understanding with you.