Senior software engineer
Senior software engineer
Originally posted by Dorj Galaa:
this is Encrypt/Decrypt example but clause
import java.io.*;
import java.security.*;
import javax.crypto.*;
class EncryptDecrypt {
public static void main(String args[])
{
try
{
// generate Cipher objects for encoding and decoding
Cipher itsocipher1 = Cipher.getInstance("DES");
Cipher itsocipher2 = Cipher.getInstance("DES");
// generate a KeyGenerator object
KeyGenerator KG = KeyGenerator.getInstance("DES");
System.out.println("Using algorithm " + KG.getAlgorithm());
// generate a DES key
Key mykey = KG.generateKey();
// initialize the Cipher objects
System.out.println("Initializing ciphers...");
itsocipher1.init(Cipher.ENCRYPT_MODE, mykey);
itsocipher2.init(Cipher.DECRYPT_MODE, mykey);
// creating the encrypting cipher stream
System.out.println("Creating the encrypting cipher stream...");
FileInputStream fis = new FileInputStream("b.txt");
CipherInputStream cis1 = new CipherInputStream(fis, itsocipher1);
// creating the decrypting cipher stream
System.out.println("Creating the decrypting cipher stream...");
CipherInputStream cis2 = new CipherInputStream(cis1, itsocipher2);
// writing the decrypted data to output file
System.out.println("Writing the decrypted data to output file " + args[1]);
FileOutputStream fos = new FileOutputStream("c.txt");
byte[] b2 = new byte[1024];
int i2 = cis2.read(b2);
while (i2 != -1)
{
fos.write(b2, 0, i2);
i2 = cis2.read(b2);
}
fos.close();
cis1.close();
cis2.close();
}
catch (Exception e)
{
System.out.println("Caught exception: " + e);
}
}
}
may me i not registered provider how to add provider or algorithm
Senior software engineer
Senior software engineer