Home » Core Java » security

security

Spring Security with Spring REST Web-service

In one of the previous example, we have studied about exposing a simple REST web-service using Spring REST and also how to consume a REST web-service. In this example, we will go a step further and attempt to access a REST Web-Service which is secured by Spring Security. We shall use Spring-REST to host the REST Web-Service. So let’s start with ...

Read More »

java.security.MessageDigest Example

The Java Cryptographic services include signature, message digest, cipher, mac and key stores. The MessageDigest class supports message digest algorithms – MD2, MD5,SHA-1, SHA-256,SHA-384 and SHA-512. SHA-256 is a 256-bit hash function to provide 128 bits of security against collision attacks. SHA-512 is a 512 bit hash function to provide 256 bits of security. A 384-bit hash is obtained by ...

Read More »

Java MessageDigest Example

In this post, we are going to discuss about the class java.security.MessageDigest 1. MessageDigest Class This MessageDigest class provides applications the functionality of a message digest algorithm, such as SHA-1 or SHA-256. Message digests are secure one-way hash functions that take arbitrary-sized data and output a fixed-length hash value. A message digest is a cryptographic hash function containing a string ...

Read More »

java.security.InvalidKeyException – How to solve InvalidKeyException

In this example we are going to talk about java.security.InvalidKeyException. It is probably the most common exception you will stumble upon when handling encryption in your Java application. java.security.InvalidKeyException is a subclass of java.security.KeyException which in turn is a subclass of java.security.GeneralSecurityException. As the name suggests, InvalidKeyException emerges when there is something wrong with the encryption key you are trying ...

Read More »

Generate a File Checksum value in Java

In this tutorial we are going to see how to generate a file’s Checksum value in Java using the SHA-1 hash function. If you are working on your applications security specs it might be useful to consider using checksums to improve the security and integrity of file transfer or file sharing actions. In short, the basic steps one should take ...

Read More »

Java DES Encryption Decryption File Tutorial

In this tutorial we are going to see how can you Encrypt and Decrypt a file in Java, using the DES encryption algorithm. DES (Data Encryption Standard) is a block cipher algorithm. It’s one of the most basic symmetric encryption mechanisms, which means that both the encryptor and the decryptor has to know the secret key in order to perform their ...

Read More »

Encrypt/Decrypt a file using DES

In this example we shall show you how to encrypt/decrypt a file using DES. To encrypt and decrypt a file using the Data Encryption Standard Algorithm, one should perform the following steps: Create a KeyGenerator for the DES algorithm and generate a secret key. Create an IvParameterSpec object, which is an implementation of the AlgorithmParameterSpec Interface, a specification of cryptographic ...

Read More »

Calculate the CRC Sum of a file

With this example we are going to demonstrate how to calculate the CRC Sum of a file. The Cyclic Redundancy Check is a good way to detect errors and changes to data. In short, in order to calculate the CRC-32 Sum of a file we implemented four different methods : The checksumInputStream(String filepath) method creates a FileInputStream by opening a ...

Read More »

Encrypt/Decrypt with salt

This is an example of how to encrypt and decrypt using a salt. The salt is random data very often used in cryptography as additional input to a hash function. Doing encryption and decryption of a String with a salt implies that you should: Read an initial String. Generate random bytes to be placed in the salt. Create a sun.misc.BASE64Decoder ...

Read More »

Check message consistency using hash functions

In this example we shall show you how to check message consistency using hash functions. We are using the java.security.MessageDigest Class, that provides the functionality of a message digest algorithm. It takes arbitrary-sized data and outputs a fixed-length hash value. To check the consistency of two messages using the MessageDigest hash function, one should perform the following steps: Create a ...

Read More »

Want to take your Java skills to the next level?

Grab our programming books for FREE!

Here are some of the eBooks you will get:

  • Spring Interview QnA
  • Multithreading & Concurrency QnA
  • JPA Minibook
  • JVM Troubleshooting Guide
  • Advanced Java
  • Java Interview QnA
  • Java Design Patterns