Home » core java » Page 20

Tag Archives: core java

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 »

Copy binary file with streams

With this example we are going to demonstrate how to copy a binary file using the FileInputStream and the FileOutputStream. In short, to copy a binary file with streams you should: Create a new FileInputStream, by opening a connection to an actual file, the file named by the path source name in the file system. Create a new FileOutputStream to ...

Read More »

Read char from console with InputStream

This is an example of how to read a char from console using an InputStream. It is an abstract class that is the superclass of all classes representing an input stream of bytes. Applications that need to define a subclass of InputStream must always provide a method that returns the next byte of input. Reading a char implies that you ...

Read More »

Read line of chars from console with InputStream

In this example we shall show you how to read a line of chars from console with an InputStream. This abstract class is the superclass of all classes representing an input stream of bytes. Applications that need to define a subclass of InputStream must always provide a method that returns the next byte of input. To read a line of ...

Read More »

Write byte array to file with FileOutputStream

With this example we are going to demonstrate how to write a byte array to a file using a FileOutputStream. The FileOutputStream is an output stream for writing data to a File or to a FileDescriptor. In short, to write a byte array to a file using a FileOutputStream you should: Create a new File instance by converting the given ...

Read More »

Append output to file with FileOutputStream

This is an example of how to append output to a file using the FileOutputStream. The FileOutputStream is an output stream for writing data to a File or to a FileDescriptor. Appending output to a file implies that you should: Create a new File instance by converting the given pathname string into an abstract pathname. Create a new FileOutputStream to ...

Read More »