//How to Encrypt and Decrypt Data In Java Using DES Algorithm
Here are the general steps to encrypt/decrypt a file in Java:
Create a Key from a given byte array for a given algorithm.
Get an instance of Cipher class for a given algorithm transformation. See document of the Cipher class for more information regarding supported algorithms and transformations.
Initialize the Cipher with an appropriate mode (encrypt or decrypt) and the given Key.
Invoke doFinal(input_bytes) method of the Cipher class to perform encryption or decryption on the input_bytes, which returns an encrypted or decrypted byte array.
Read an input file to a byte array and write the encrypted/decrypted byte array to an output file accordingly.
Now, let’s see some real examples.
=============================================================
import java.io.*;
import javax.crypto.*;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
class Desal
{
public static void main(String []s)
{
try
{
String st="Hello";
System.out.println("Real String : "+ st);
byte str[]=st.getBytes();
Cipher c=Cipher.getInstance("DES");
KeyGenerator kg=KeyGenerator.getInstance("DES");
SecretKey sk=kg.generateKey();
//ENCRYPT_MODE
c.init(Cipher.ENCRYPT_MODE,sk);
byte ct[]=c.doFinal(str);
System.out.println("ENCRYPT_MODE DATA : "+ new String(ct));
//DECRYPT_MODE
c.init(Cipher.DECRYPT_MODE,sk);
byte ct1[]=c.doFinal(ct);
System.out.println("DECRYPT_MODE DATA : "+ new String(ct1));
}
catch(Exception e)
{
System.out.println(e);
}
}
}
==============================================
encryption and decryption in java example,
string encryption and decryption in java,
password encryption and decryption in java,
java code to encrypt and decrypt a string,
java code for encryption and decryption of files,
simple encryption and decryption in java,
encryption and decryption in java source code,
encryption and decryption in java example md5
www.patelwala.com
www.readranks.com
~-~~-~~~-~~-~
Please watch: "How to online money earn from Flipkart without selling any products"
• Video
~-~~-~~~-~~-~
En esta página del sitio puede ver el video en línea How to Encrypt and Decrypt Data In Java Using DES Algorithm de Duración hora minuto segunda en buena calidad , que subió el usuario Inside App 16 febrero 2017, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 2,631 veces y le gustó 14 a los espectadores. Disfruta viendo!