Home » Core Java » crypto

crypto

Get bytes of generated symmetric key

In this example we shall show you how to get the bytes of a generated symmetric key. To get the bytes of a generated symmetric key one should perform the following steps: Create a new KeyGenerator for the DESede algorithm. Generate a SecretKey, using generateKey() API method of KeyGenerator. Use getEncoded() API method of SecretKey, to get a byte array ...

Read More »

Generate Message Authentication Code (MAC)

With this example we are going to demonstrate how to generate a Message Authentication Code (MAC). We are using the Mac class that provides the functionality of a “Message Authentication Code” (MAC) algorithm. In short, to generate a Message Authentication Code you should: Create a new KeyGenerator for the HmacMD5 algorithm. Generate a SecretKey, using generateKey() API method of KeyGenerator. ...

Read More »

Encrypt/Decrypt file/stream with DES

This is an example of how to encrypt or decrypt a file or stream with DES. DES in computing refers to the Data Encryption Standard and is supported by Java. To encrypt or decrypt a file or stream with DES one should perform the following steps: Get an instance of a KeyGenerator with DES as algorithm Generate a key (SecretKey) ...

Read More »

List available Encryption/Decryption algorithms

This is an example of how to list all the available Encryption/Decryption algorithms. In order to do so we have created a method, Set<String> getAlgorithms(String serviceType). The method gets a String parameter that is the serviceType for which it will return the algorithms. The steps of the method are the ones below: Create a new Set of String elements, to ...

Read More »

List available cryptographic services

In this example we shall show you how to list all the available cryptographic services. To list all the available cryptographic services one should perform the following steps: Create a new Set of String elements, to hold the services. Use getProviders() API method of Security to get an array of the Providers. For every Provider get a view of the ...

Read More »

Encrypt/Decrypt with DES using pass phrase

With this example we are going to demonstrate how to encrypt/decrypt with DES using a password phrase. DES in computing refers to the Data Encryption Standard and is supported by Java. In short, to encrypt/decrypt with DES using a password phrase you should: Create a String password that can be used with password-based encryption (PBE). Provide password, salt, iteration count ...

Read More »

Encrypt/Decrypt object with DES

This is an example of how to encrypt and decrypt an object with DES. DES in computing refers to the Data Encryption Standard and is supported by Java. To encrypt and decrypt an object with DES you should: Create a class to represent the object to be encrypted. SecretObject implements Serializable. It has a String property. Generate a SecretKey using ...

Read More »

Encrypt/Decrypt string with DES

In this example we shall show you how to encrypt and decrypt a String with DES. DES in computing refers to the Data Encryption Standard and is supported by Java. To encrypt and decrypt a String with DES one should perform the following steps: Generate a SecretKey using DES algorithm, with the KeyGenerator generateKey() API method. Initialize two Ciphers, one ...

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