Home » Core Java » security (page 2)

security

SHA-1 hash function example

With this example we are going to demonstrate how to make a SHA-1 hash function example. The Secure Hash Algorithm is a family of cryptographic functions. In short, to compute the hash value of a String with the SHA-1 algorithm, you should: Create a MessageDigest Object that implements the SHA-1 algorithm, using the getInstance(String algorithm) API method. Reset the MessageDigest ...

Read More »

Diffie-Helman key pair generation and parameters

This is an example of how to generate key pairs with the Diffie-Helman algorithm. The DH algorithm is be used to generate private/public key pairs. The private key can be used to generate a digital signature for a document by the owner of the document. Then the public key can be used by the one who receives the document to ...

Read More »

Simple symmetric key encrypt/decrypt

In this example we shall show you how to encrypt and decrypt using a symmetric key. In the case of a symmetric key, the same key is used to encrypt and decrypt the data. Because both parties have the same key, the decryption essentially is performed by reversing some part of the encryption process. To encrypt and decrypt a String ...

Read More »

PBE with a PBEParameterSpec example

With this example we are going to demonstrate how to make PBE using a PBEParameterSpec. In short, to make a Password-Based Encryption using a PBEParameterSpec you should: Create three byte arrays, the first one from the String message to be encrypted, the second one to be used as a key and the third one to be used as an initialization ...

Read More »

DES with CBC using a nonce IV

This is an example of how to make a DES example in CBC mode using a nonce Iv. Encrypting data with the Data Encryption algorithm, in Chipher Block Chaining mode and with an initialization vector implies that you should: Create three byte arrays, the first one for the password, the second one for the key and the third one for ...

Read More »

DES with ECB example

In this example we shall show you how to encrypt data using the DES algorithm in ECB mode. To encrypt a String message with the Data Encryption algorithm in Electronic Code Book mode one should perform the following steps: Create a byte array from the initial String message, and a byte array to be used as a key. Create a ...

Read More »

DES with CBC example

With this example we are going to demonstrate how to encrypt data using the DES algorithm in CBC mode. In short, to encrypt/decrypt a String message with the Data Encryption Standard algorithm, in Chipher Block Chaining mode you should: Create a byte array to be used as initial input, a byte array to be used as a key and a ...

Read More »

DES with CTR example

This is an example of how to encrypt data using the DES algorithm in CTR mode. Doing data encryption with the Data Encryption Standard algorithm, in CTR mode implies that you should: Create a byte array to be used as initial password to be encrypted, a byte array to be used as a key and a a byte array to ...

Read More »

Encrypt/Decrypt with with AES/ECB/PKCS7Padding

In this example we shall show you how to encrypt/decrypt data with the AES/ECB/PKCS 7Padding. To encrypt data using the AES algorithm,in ECB mode and with PKCS7Padding one should perform the following steps: Create a byte array to be used as input to be encrypted and a byte array to be used as a key. Create a new SecretKeySpec for ...

Read More »

Symmetric encryption example

With this example we are going to demonstrate how to make a symmetric encryption and decryption. In symmetric encryption the same key is used for both encryption of plaintext and decryption of ciphertext. In short, to make a symmetric encryption you should: Create a byte array from the initial password and a byte array from the initial key. Create a ...

Read More »