Using HMac Sha256 for Message Authentication (MAC) in Java

Secure message authentication using a MAC generated from a secret key with a password.

“There is some good in this world, and it’s worth fighting for.” ― J.R.R. Tolkien, The Two Towers

1. Introduction

A Message Authentication Code or a MAC provides a way to guarantee that a message (a byte array) has not been modified in transit. It is similar to a message digest to calculate a hash, but uses a secret key so that only a person with the secret key can verify the authenticity of the message.

Continue reading “Using HMac Sha256 for Message Authentication (MAC) in Java”

AES Encryption and Decryption Using a Password in Java

Encrypt a file using a password with strong AES security.

“My tastes are simple: I am easily satisfied with the best.”
― Winston S. Churchill

1. Introduction

In a previous article, we have explained how to use AES for encryption and decryption. After encryption, the AES key will need to be communicated to the receiver via a secure channel for decrypting the file.

Continue reading “AES Encryption and Decryption Using a Password in Java”

Encrypt and Sign a File Using RSA in Java

Securely exchange a file with another person using RSA for encryption and digital signature to ensure authentication.

“To acquire knowledge, one must study;
but to acquire wisdom, one must observe.”
― Marilyn Vos Savant

1. Introduction

We have previously covered using RSA for file encryption in java. We have also covered in a separate article the process of generating a digital signature for a file and verification using RSA. Let us now combine the two and develop a procedure for encrypting a file and generating a digital signature for exchange between two parties.

Continue reading “Encrypt and Sign a File Using RSA in Java”

Using AES With RSA for File Encryption and Decryption in Java

AES can be used for encrypting the file and RSA for encrypting the AES key.

“The secret of education lies in respecting the pupil.”
― Ralph Waldo Emerson

1. Introduction

In the previous part of this article, we covered the use of RSA for file encryption and decryption in java. Using RSA directly for file encryption will not work since it can only be used with small buffer sizes. In our particular case, with an RSA key size of 2048 bits, we ran into a limitation of a maximum of 245 bytes for the data size.

Continue reading “Using AES With RSA for File Encryption and Decryption in Java”

File Encryption and Decryption using RSA in Java

Use RSA for File Encryption and Decryption in Java

“If you can’t do anything about it, laugh like hell.”
― David Cook

1. Introduction

RSA (Rivest–Shamir–Adleman) is an asymmetric encryption algorithm widely used in public-key cryptography today. The word asymmetric denotes the use of a pair of keys for encryption – a public key and a private key. When data is encrypted by one key, it can only be decrypted using the other key. The public key is publicized and the private key is kept secret.

Continue reading “File Encryption and Decryption using RSA in Java”

How to Use AES for Encryption and Decryption in Java

Learn how to use AES for encryption and decryption in Java

“There’s as many atoms in a single molecule of your DNA as there are stars in the typical galaxy. We are, each of us, a little universe.” ― Neil deGrasse Tyson, Cosmos

1. Introduction

The Advanced Encryption Standard (AES) is a standard for encryption and decryption that has been approved by the U.S. NIST (National Institute of Standards and Technology) in 2001. It is more secure than the previous encryption standard DES (Data Encryption Standard) and 3DES (Triple-DES). You should be using AES for all symmetric encryption needs in preference to DES and 3DES (which are now deprecated).

Continue reading “How to Use AES for Encryption and Decryption in Java”

JDBC – More About Columns in an SQL Query

Learn how to get details of columns in an SQL query with JDBC.

1. Introduction

An earlier article covered the basics of JDBC (Java DataBase Connectivity) and how to perform SQL queries on a MySQL database. Frequently, it is useful to obtain more information about the columns in a query. These include: the number of columns, column names and types, etc. Maybe you want to build a GUI table showing the results of a query, which requires the names of the columns and more. This article will show you how to retrive the information using JDBC.

Continue reading “JDBC – More About Columns in an SQL Query”

JDBC MySQL Tutorial

A simple tutorial showing the basics of using JDBC database API.

“A man’s true character comes out when he’s drunk.”
― Charlie Chaplin

1. Introduction

JDBC stands for Java DataBase Connectivity and is the standard API (application programming interface) java provides for working with databases. JDBC, as a standard, is built into the java platform. To connect with and use a database, you need an additional component called a jdbc driver, which is specific to the type of database you are working with, such as MySQL, SQL Server, etc. In other words, the JDBC API consists of a small number of classes and a bunch of interfaces, the implementation provided by the actual database vendor. This is illustrated by the figure below.

Continue reading “JDBC MySQL Tutorial”

What is the Python Yield Statement?

Learn about the Python yield statement which is used to create generators.

“Count your age by friends, not years. Count your life by smiles, not tears.”
― John Lennon

1. Introduction

Python provides an yield statement which allows you to create generator functions. What is a generator function and how does the yield statement help with it? Let us find out in this article.

Continue reading “What is the Python Yield Statement?”

What are JavaScript Closures?

Learn about JavaScript Closures.

“Everything must be made as simple as possible. But not simpler.”
― Albert Einstein

1. Introduction

JavaScript supports closures which is a concept that is somewhat hard to understand, so let us step you through some examples to help.

Continue reading “What are JavaScript Closures?”