RC4
/*
* RC4
*from http://sagarlone.weebly.com/network-security-algorithm-implementation.html
*/
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
public class RC4Demo
{
public static void main(String[] args) {
try {
//get message
System.out.print("Enter message: ");
String msg=new java.util.Scanner(System.in).next();
String ; //algorithtm type
// String e; // encoding type
// key generation setps
byte key[]="ABCD123456EFGH15".getBytes();
SecretKeySpec s=new SecretKeySpec(key, type);
// Cipher creation
Cipher c=Cipher.getInstance(type);
c.init(Cipher.ENCRYPT_MODE,s);
byte ct[]=c.doFinal(msg.getBytes());
//
String cts=new String(ct);
System.out.println("Cipher text: "+ct);
// decryption
Cipher c1=Cipher.getInstance(type);
c1.init(Cipher.DECRYPT_MODE,s);
String ot=new String(c1.doFinal(ct));
System.out.println("Decrypted message: "+ot);
} catch (Exception ex) {
System.out.println(ex);
}
}
}
* RC4
*from http://sagarlone.weebly.com/network-security-algorithm-implementation.html
*/
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
public class RC4Demo
{
public static void main(String[] args) {
try {
//get message
System.out.print("Enter message: ");
String msg=new java.util.Scanner(System.in).next();
String ; //algorithtm type
// String e; // encoding type
// key generation setps
byte key[]="ABCD123456EFGH15".getBytes();
SecretKeySpec s=new SecretKeySpec(key, type);
// Cipher creation
Cipher c=Cipher.getInstance(type);
c.init(Cipher.ENCRYPT_MODE,s);
byte ct[]=c.doFinal(msg.getBytes());
//
String cts=new String(ct);
System.out.println("Cipher text: "+ct);
// decryption
Cipher c1=Cipher.getInstance(type);
c1.init(Cipher.DECRYPT_MODE,s);
String ot=new String(c1.doFinal(ct));
System.out.println("Decrypted message: "+ot);
} catch (Exception ex) {
System.out.println(ex);
}
}
}