Вы находитесь на странице: 1из 75

KINGSTON ENGINEERING COLLEGE

DEPARTMENT OF COMPUTER SCIENCE


ENGINEERING
SEVENTH SEMESTER

LAB MATERIAL
CS6711 SECURITY LABORATORY

Prepared By
M.AZHAGIRI & P.KRISHNAMOORTHY
Assistant Professor
Department of Computer Science Engineering
Kingston Engineering College
2016

CS6711

SECURITY LABORATORY

LTPC
0032

OBJECTIVES: The student should be made to:

Be exposed to the different cipher techniques


Learn to implement the algorithms DES, RSA,MD5,SHA-1
Learn to use network security tools like GnuPG, KF sensor, Net Strumbler

LIST OF EXPERIMENTS:
1. Implement the following SUBSTITUTION & TRANSPOSITION TECHNIQUES
concepts:
a) Caesar Cipher
b) Playfair Cipher
c) Hill Cipher
d) Vigenere Cipher
e) Rail fence row & Column Transformation
2. Implement the following algorithms
a) DES
b) RSA Algorithm
c) Diffiee-Hellman
d) MD5
e) SHA-1
3. Implement the SIGNATURE SCHEME - Digital Signature Standard
4. Demonstrate how to provide secure data storage, secure data transmission and for creating
digital signatures (GnuPG).
5. Setup a honey pot and monitor the honeypot on network (KF Sensor)
6. Installation of root kits and study about the variety of options
7. Perform wireless audit on an access point or a router and decrypt WEP and WPA.( Net
Stumbler)
8. Demonstrate intrusion detection system (ids) using any tool (snort or any other s/w)
TOTAL: 45 PERIODS
OUTCOMES: At the end of the course, the student should be able to
Implement the cipher techniques
Develop the various security algorithms
Use different open source tools for network security and analysis
LIST OF EQUIPMENT FOR A BATCH OF 30 STUDENTS:
SOFTWARE: C / C++ / Java or equivalent compiler GnuPG, KF Sensor or Equivalent,
Snort, Net Stumbler or Equivalent
HARDWARE: Standalone desktops - 30 Nos. (or) Server supporting 30 terminals or more.

LIST OF EXPERIMENTS
1. Write a program to implement the Caesar Cipher
2. Write a program to implement the Playfair Cipher
3. Write a program to implement the Hill Cipher
4. Write a program to implement the Vigenere Cipher
5. Write a program to implement the Rail fence row & Column Transformation
6. Write a program to implement the DES algorithms
7. Write a program to implement the RSA Algorithm
8. Write a program to implement the Diffiee-Hellman algorithms
9. Write a program to implement the MD5 algorithms
10. Write a program to implement the SHA-1 algorithms
11. Implement the SIGNATURE SCHEME Digital Signature Standard
12. Demonstrate how to provide secure data storage, secure data transmission and for
creating digital signatures Using GnuPG.
13. Setup a honey pot and monitor the honeypot on network using KF Sensor
14. Installation of root kits and study about the variety of options
15. Perform wireless audit on an access point or a router and decrypt WEP and WPA
using Net Stumbler
16. Demonstrate intrusion detection system (ids) using any tool using snort

Ex.No: 1

IMPLEMENTATION OF CAESAR CIPHER

AIM
To write a Java Program for implementing Caesar Cipher.
ALGORITHM
Step 1: Start the program.
Step 2: Define a class Caesar Cipher.
Step 3: Declare a string ALPHABET.
Step 4: Define a function encrypt () to produce a cipher text and decrypt () to
reproduce the plain text.
Step 5: Define a main (), get the string and call encrypt() to encrypt the string and
decrypt() to reproduce the plain text and display it.
Step 6: Stop the program.
PROGRAM //file name CeaserCipher.java
import java.util.*;
class basic{
String allChar="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int indexOfChar(char c)
{
for(int i=0;i< allChar.length();i++)
{
if(allChar.charAt(i)==c)
return i;
}
return -1;
}
char charAtIndex(int pos)
{
return allChar.charAt(pos);
}
}
class Ceaser{
basic b=new basic();
String Encrypt(String plainText,int key)

{
plainText=plainText.toUpperCase();
String cipherText=" ";
for(int i=0;i< plainText.length();i++)
{
int index=b.indexOfChar(plainText.charAt(i));
if(index==-1)
{
cipherText+=plainText.charAt(i);
continue;
}
if((index+key)%26==0)
{
cipherText+=b.charAtIndex(index+key);
}
else
{
cipherText+=b.charAtIndex((index+key)%26);
}
}
return cipherText;
}
String Decrypt(String cipherText,int key)
{
cipherText=cipherText.toUpperCase();
String decryptedText="";
for(int i=0;i< cipherText.length();i++)
{
int index=b.indexOfChar(cipherText.charAt(i));
if(index==-1)
{
decryptedText+=cipherText.charAt(i);
continue;
}

if((index-key)>=0)
{
decryptedText+=b.charAtIndex(index-key);
}
else
{
decryptedText+=b.charAtIndex((index-key)+26);
} }
return decryptedText;
}
void bruteForce(String cipherText)
{
cipherText=cipherText.toUpperCase();
for(int k=0;k< 26;k++)
{
String decryptedText="";
int key=k;
for(int i=0;i< cipherText.length();i++)
{
int index=b.indexOfChar(cipherText.charAt(i));
if(index==-1)
{
decryptedText+=cipherText.charAt(i);
continue;
}
if((index-key)>=0)
{
decryptedText+=b.charAtIndex(index-key);
}
else
{
decryptedText+=b.charAtIndex((index-key)+26);
}

System.out.println("Decrypted Text Using key"+key+":"+decryptedText);

} }}
class CeaserCipher{
public static void main(String args[])throws Exception
{
Scanner scn=new Scanner(System.in);
String plainText,cipherText;
int key;
System.out.println("Enter Plaintext message:");
plainText=scn.nextLine();
System.out.println("Enter key for Encryption:");
key=scn.nextInt();
Ceaser cipher=new Ceaser();
cipherText=cipher.Encrypt(plainText,key);
System.out.println("Encrypted Ciphertext is:"+cipherText);
String decryptedText=cipher.Decrypt(cipherText,key);
System.out.println("Decrypted Ciphertext is:"+decryptedText);
System.out.println("Do you want to apply brute force on Ciphertext ?press 1 otherwise press
anykey");
int choice=scn.nextInt();
if(choice==1)
cipher.bruteForce(cipherText);
}
}
OUTPUT
Enter Plaintext message:
HELLO
Enter key for Encryption: 5
Encrypted Ciphertext is: MJQQT
Decrypted Ciphertext is: HELLO
Do you want to apply brute force on Ciphertext ? press 1 otherwise press any key: 1

RESULT
Thus java program to implement Caesar Cipher was written, executed and output is verified
successfully.

Ex.No: 2

IMPLEMENTATION OF PLAYFAIR CIPHER

AIM
To write a Java program for implementing Playfair Cipher.
ALGORITHM
Step 1: Start the program.
Step 2: Define a class Basic to find the index of a char.
Step 3: Define a class PlayFair to define the key matrix, find the row position, column
position, encrypt the text and decrypt the text.
Step 4: Define a class PlayFairCipher, to get the plain text and then to encrypt and
decrypt the text.
Step 5: Display the encrypted text and decrypted text.
Step 6: Stop the program.

PROGRAM //File Name: PlayFairCipher.java

import java.util.*;
class Basic{
String allChar="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
boolean indexOfChar(char c)
{
for(int i=0;i < allChar.length();i++)
{
if(allChar.charAt(i)==c)
return true;
}
return false;
}
}
class PlayFair{
Basic b=new Basic();
char keyMatrix[][]=new char[5][5];
boolean repeat(char c)
{

if(!b.indexOfChar(c))
{
return true;
}
for(int i=0;i < keyMatrix.length;i++)
{
for(int j=0;j < keyMatrix[i].length;j++)
{
if(keyMatrix[i][j]==c || c=='J')
return true;
}
}
return false;
}
void insertKey(String key)
{
key=key.toUpperCase();
key=key.replaceAll("J", "I");
key=key.replaceAll(" ", "");
int a=0,b=0;
for(int k=0;k < key.length();k++)
{
if(!repeat(key.charAt(k)))
{
keyMatrix[a][b++]=key.charAt(k);
if(b>4)
{
b=0;
a++;
}
}
}
char p='A';
while(a < 5)

{
while(b < 5)
{
if(!repeat(p))
{
keyMatrix[a][b++]=p;
}
p++;
}
b=0;
a++;
}
System.out.print("-------------------------Key Matrix-------------------");
for(int i=0;i < 5;i++)
{
System.out.println();
for(int j=0;j < 5;j++)
{
System.out.print("\t"+keyMatrix[i][j]);
}
}
System.out.println("\n---------------------------------------------------------");
}
int rowPos(char c)
{
for(int i=0;i < keyMatrix.length;i++)
{
for(int j=0;j < keyMatrix[i].length;j++)
{
if(keyMatrix[i][j]==c)
return i;
}
}
return -1;

}
int columnPos(char c)
{
for(int i=0;i < keyMatrix.length;i++)
{
for(int j=0;j < keyMatrix[i].length;j++)
{
if(keyMatrix[i][j]==c)
return j;
}
}
return -1;
}

String encryptChar(String plain)


{
plain=plain.toUpperCase();
char a=plain.charAt(0),b=plain.charAt(1);
String cipherChar="";
int r1,c1,r2,c2;
r1=rowPos(a);
c1=columnPos(a);
r2=rowPos(b);
c2=columnPos(b);
if(c1==c2)
{
++r1;
++r2;
if(r1>4)
r1=0;
if(r2>4)
r2=0;
cipherChar+=keyMatrix[r1][c2];
cipherChar+=keyMatrix[r2][c1];

}
else if(r1==r2)
{
++c1;
++c2;
if(c1>4)
c1=0;
if(c2>4)
c2=0;
cipherChar+=keyMatrix[r1][c1];
cipherChar+=keyMatrix[r2][c2];
}
else{
cipherChar+=keyMatrix[r1][c2];
cipherChar+=keyMatrix[r2][c1];
}
return cipherChar;
}
String Encrypt(String plainText,String key)
{
insertKey(key);
String cipherText="";
plainText=plainText.replaceAll("j", "i");
plainText=plainText.replaceAll(" ", "");
plainText=plainText.toUpperCase();
int len=plainText.length();
// System.out.println(plainText.substring(1,2+1));
if(len/2!=0)
{
plainText+="X";
++len;
}
for(int i=0;i < len-1;i=i+2)
{

cipherText+=encryptChar(plainText.substring(i,i+2));
cipherText+=" ";
}
return cipherText;
}
String decryptChar(String cipher)
{
cipher=cipher.toUpperCase();
char a=cipher.charAt(0),b=cipher.charAt(1);
String plainChar="";
int r1,c1,r2,c2;
r1=rowPos(a);
c1=columnPos(a);
r2=rowPos(b);
c2=columnPos(b);
if(c1==c2)
{
--r1;
--r2;
if(r1 < 0)
r1=4;
if(r2 < 0)
r2=4;
plainChar+=keyMatrix[r1][c2];
plainChar+=keyMatrix[r2][c1];
}
else if(r1==r2)
{
--c1;
--c2;
if(c1 < 0)
c1=4;
if(c2 < 0)
c2=4;

plainChar+=keyMatrix[r1][c1];
plainChar+=keyMatrix[r2][c2];
}
else{
plainChar+=keyMatrix[r1][c2];
plainChar+=keyMatrix[r2][c1];
}
return plainChar;
}
String Decrypt(String cipherText,String key)
{
String plainText="";
cipherText=cipherText.replaceAll("j", "i");
cipherText=cipherText.replaceAll(" ", "");
cipherText=cipherText.toUpperCase();
int len=cipherText.length();
for(int i=0;i < len-1;i=i+2)
{
plainText+=decryptChar(cipherText.substring(i,i+2));
plainText+=" ";
}
return plainText;
}
}

class PlayFairCipher{
public static void main(String args[])throws Exception
{
PlayFair p=new PlayFair();
Scanner scn=new Scanner(System.in);
String key,cipherText,plainText;
System.out.println("Enter plaintext:");
plainText=scn.nextLine();

System.out.println("Enter Key:");
key=scn.nextLine();
cipherText=p.Encrypt(plainText,key);
System.out.println("Encrypted text:");
System.out.println("---------------------------\n"+cipherText);
System.out.println("-------------------------------");
String encryptedText=p.Decrypt(cipherText, key);
System.out.println("Decrypted text:" );
System.out.println("------------------------\n"+encryptedText);
System.out.println("----------------------");
}
}
OUTPUT
Enter plaintext:
PLAYCIPHERISONEOFGOODCIPHER
Enter Key:
SECRETKEY
-------------------------Key Matrix------------------S

T
D
L

--------------------------------------------------------Encrypted text:
--------------------------------------------------------QI BA RH OI CT FR PO CN GH WW AT PX GC BR
--------------------------------------------------------Decrypted text:
--------------------------------------------------------PL AY CI PH ER IS ON EO FG OO DC IP HE RX
---------------------------------------------------------

RESULT
Thus java program to implement PlayFair Cipher was written, executed and output is verified
successfully.

Ex.No: 3

IMPLEMENTATION OF HILL CIPHER

AIM:
To write a Java Program for implementing Hill Cipher.

ALGORITHM
Step 1: Start the program.
Step 2: Define a class HillCipher, in that declare 2 array one for key, other for inverse
key and define a string key.
Step 3: In this class, define a main(), get the choice to encrypt or decrypt.
Step 4: Based on the choice call encrypt() and decrypt() to find cipher and plain text.
Step 5: Display the result.
Step 6: Stop the program.

// File name:HillCipher.java
import java.util.*;
class Basic{
String allChar="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int indexOfChar(char c)
{
for(int i=0;i < allChar.length();i++)
{
if(allChar.charAt(i)==c)
return i;
}
return -1;
}
char charAtIndex(int pos)
{
return allChar.charAt(pos);
}
}
class Hill{

Hill(int block)
{
this.block=block;
}
Basic b1=new Basic();
int block=2;
int key[][]=new int[block][block];
void keyInsert()throws Exception
{
Scanner scn=new Scanner(System.in);
System.out.println("Enter key Matrix");
for(int i=0;i < block;i++)
{
for(int j=0;j < block;j++)
{
key[i][j]=scn.nextInt();
}
}
}
void KeyInverseInsert()throws Exception
{
Scanner scn=new Scanner(System.in);
System.out.println("Enter key Inverse Matrix:");
for(int i=0;i < block;i++)
{
for(int j=0;j < block;j++)
{
key[i][j]=scn.nextInt();
}
}
}
String encryptBlock(String plain)throws Exception
{
plain=plain.toUpperCase();

int a[][]=new int[block][1],sum=0;


int cipherMatrix[][]=new int[block][1];
String cipher="";
for(int i=0;i < block;i++)
{
a[i][0]=b1.indexOfChar(plain.charAt(i));
}
for(int i=0;i < block;i++)
{
for(int j=0;j < 1;j++)
{
for(int k=0;k < block;k++)
{
sum=sum+key[i][k]*a[k][j];
}
cipherMatrix[i][j] = sum%26;
sum = 0;
}
}
for(int i=0;i < block;i++)
{
cipher+=b1.charAtIndex(cipherMatrix[i][0]);
}
return cipher;
}
String encrypt(String plainText)throws Exception
{
String cipherText="";
keyInsert();
plainText=plainText.toUpperCase();
int len=plainText.length();
// System.out.println(plainText.substring(1,2+1));
while(len%block!=0)
{

plainText+="X";
System.out.println(len);
len=plainText.length();
}
for(int i=0;i < len-1;i=i+block)
{
cipherText+=encryptBlock(plainText.substring(i,i+block));
cipherText+=" ";
}
return cipherText;
}
String decryptBlock(String cipher)throws Exception
{
cipher=cipher.toUpperCase();
int a[][]=new int[block][1],sum=0;
int plainMatrix[][]=new int[block][1];
String plain="";
for(int i=0;i < block;i++)
{
a[i][0]=b1.indexOfChar(cipher.charAt(i));
}
for(int i=0;i < block;i++)
{
for(int j=0;j < 1;j++)
{
for(int k=0;k < block;k++)
{
sum=sum+key[i][k]*a[k][j];
}
while(sum < 0)
{
sum+=26;
}
plainMatrix[i][j] = sum;

sum = 0;
}
}
for(int i=0;i < block;i++)
{
plain+=b1.charAtIndex(plainMatrix[i][0]);
}
return plain;
}
String Decrypt(String cipherText)throws Exception
{
String plainText="";
KeyInverseInsert();
cipherText=cipherText.replaceAll(" ", "");
cipherText=cipherText.toUpperCase();
int len=cipherText.length();
for(int i=0;i < len-1;i=i+block)
{
plainText+=decryptBlock(cipherText.substring(i,i+block));
plainText+=" ";
}
return plainText;
}
}
class HillCipher{
public static void main(String args[])throws Exception
{
String plainText,cipherText;
int block;
Scanner scn=new Scanner(System.in);
System.out.println("Enter plain-text:");
plainText=scn.nextLine();
System.out.println("Enter block size of matrix:");
block=scn.nextInt();

Hill hill=new Hill(block);


plainText=plainText.replaceAll(" ", "");
cipherText= hill.encrypt(plainText);
System.out.println("Encrypted Text is:\n"+cipherText);
String decryptedText= hill.Decrypt(cipherText);
System.out.println("Decrypted Text is:\n"+decryptedText);
}
}
OUTPUT

Enter plain-text: meet


Enter block size of matrix: 2
Enter key Matrix
31
52
Encrypted Text is:
OQ FG
Enter key Inverse Matrix:
2 -1
-5 3
Decrypted Text is:
ME ET

RESULT
Thus java program to implement Hill Cipher was written, executed and output is verified
successfully.

Ex.No: 4

IMPLEMENTATION OF VIGENERE CIPHER

AIM
To write a Java Program for implementing Vigenere Cipher.
ALGORITHM
Step 1: Start the program.
Step 2: Define a class VC1, in that define encipher() to produce a cipher text.
Step 3: Define decipher() to reproduce the plain text.
Step 4: Define a shift() to shift the values.
Step 5: In main(), define the text and key values and call the encipher() to encrypt and
decipher() to decrypt the encrypted text.
Step 6: Display the results.
Step 7: Stop the program.
vigenerecipher
import java.io.*;
public class vigenerecipher
{
public String encrypt(String keyword, String line)
{
String result=" ";
int offset;
int j=0,shift;
for(int i=0;i<line.length();i++)
{
shift=((int)keyword.charAt(j))-97;
j++;
j%=keyword.length();
offset=((int)line.charAt(i)+shift)%256;
result+=(char)(offset);
}
return result;
}
public String decrypt(String keyword, String line)
{
String result="";

int offset;
int j=0,shift;
for(int i=0;i<line.length();i++)
{
shift=((int)keyword.charAt(j))-97;
j++;
j%=keyword.length();
offset=((int)line.charAt(i)-shift)%256;
if(offset<0)
offset+=256;
result+=(char)(offset);
}
return result;
}
public static void main(String args[])throws IOException
{
vigenerecipher obj=new vigenerecipher();
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
int choice;
System.out.println("Menu:\n1: Encryption\n2: Decryption");
choice=Integer.parseInt(in.readLine());
System.out.println("Enter the keyword: ");
String keyword=in.readLine();
System.out.println("Enter the line: ");
String line=in.readLine();
System.out.println("Result:");
switch(choice)
{
case 1:System.out.println(obj.encrypt(keyword,line));
break;
case 2:System.out.println(obj.decrypt(keyword,line));
break;
default:
System.out.println("Invalid input!");

break;
}
}
}

Output
Menu
1.Encryption
2.Decryption
1(Encryption)
Enter the Keyword : HELLO
Enter the Line Number:1
Result :8
2(Decryption)
Enter the Keyword : HELLO
Enter the Line Number:8
Result :1

RESULT
Thus java program to implement Vigenere Cipher was written, executed and output is
verified successfully.

Ex.No: 5

IMPLEMENTATION OF RAIL FENCE

ROW & COLUMN

TRANSFORMATION

AIM
To write a Java Program for implementing Rail Fence Row & Column
Transformation.
ALGORITHM
Step 1: Start the program.
Step 2: Define a class railfencebasic, in that define Encryption() to produce cipher
text.
Step 3: Define Decryption() to produce decipher text.
Step 4: Define a class railfencecipher, in that define main() and input the text to cipher
and decipher it.
Step 5: Display the results.
Step 6: Stop the program.

PROGRAM // File Name: RailFence.java


import java.util.*;
class RailFenceBasic{
int depth;
String Encryption(String plainText,int depth)throws Exception
{
int r=depth,len=plainText.length();
int c=len/depth;
char mat[ ][ ]=new char[r][c];
int k=0;
String cipherText="";
for(int i=0;i< c;i++)
{
for(int j=0;j< r;j++)
{
if(k!=len)
mat[j][i]=plainText.charAt(k++);
else

mat[j][i]='X';
}
}
for(int i=0;i< r;i++)
{
for(int j=0;j< c;j++)
{
cipherText+=mat[i][j];
}
}
return cipherText;
}
String Decryption(String cipherText,int depth)throws Exception
{
int r=depth,len=cipherText.length();
int c=len/depth;
char mat[][]=new char[r][c];
int k=0;
String plainText="";
for(int i=0;i< r;i++)
{
for(int j=0;j< c;j++)
{
mat[i][j]=cipherText.charAt(k++);
}
}
for(int i=0;i< c;i++)
{
for(int j=0;j< r;j++)
{
plainText+=mat[j][i];
}
}
return plainText;

}
}
class RailFence{
public static void main(String args[])throws Exception
{
RailFenceBasic rf=new RailFenceBasic();
Scanner scn=new Scanner(System.in);
int depth;
String plainText,cipherText,decryptedText;
System.out.println("Enter plain text:");
plainText=scn.nextLine();
System.out.println("Enter depth for Encryption:");
depth=scn.nextInt();
cipherText=rf.Encryption(plainText,depth);
System.out.println("Encrypted text is:\n"+cipherText);
decryptedText=rf.Decryption(cipherText, depth);
System.out.println("Decrypted text is:\n"+decryptedText);
}
}

OUTPUT
Enter plain text:
railfencecipher
Enter depth for Encryption:
3
Encrypted text is:
rlnchafcieieepr
Decrypted text is:
railfencecipher

RESULT
Thus java program to implement Rail Fence Row & Column Transformation was written,
executed and output is verified successfully.

Ex.No:6

IMPLEMENTATION OF DES

AIM
To write a Java Program for implementing DES.
ALGORITHM
Step 1: Start the program.
Step 2: Define a class DES, in that define a constructor to display the encrypted and
decrypted message.
Step 3: Define generateSymmetricKey(), to generate the key.
Step 4: Define encrypt() to encrypt the plain text.
Step 5: Define decrypt() to decrypt the ciphered text.
Step 6: Define main() to declare object for the class.
Step 7: Stop the program.
PROGRAM /*DES.JAVA*/
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.security.spec.KeySpec;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESedeKeySpec;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
public class DES {
private static final String UNICODE_FORMAT = "UTF8";
public static final String DESEDE_ENCRYPTION_SCHEME = "DESede";
private KeySpec myKeySpec;
private SecretKeyFactory mySecretKeyFactory;
private Cipher cipher;
byte[] keyAsBytes;
private String myEncryptionKey;
private String myEncryptionScheme;
SecretKey key;
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

public DES() throws Exception {


// TODO code application logic here
myEncryptionKey = "ThisIsSecretEncryptionKey";
myEncryptionScheme = DESEDE_ENCRYPTION_SCHEME;
keyAsBytes = myEncryptionKey.getBytes(UNICODE_FORMAT);
myKeySpec = new DESedeKeySpec(keyAsBytes);
mySecretKeyFactory = SecretKeyFactory.getInstance(myEncryptionScheme);
cipher = Cipher.getInstance(myEncryptionScheme);
key = mySecretKeyFactory.generateSecret(myKeySpec);
}
public String encrypt(String unencryptedString) {
String encryptedString = null;
try {
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] plainText = unencryptedString.getBytes(UNICODE_FORMAT);
byte[] encryptedText = cipher.doFinal(plainText);
BASE64Encoder base64encoder = new BASE64Encoder();
encryptedString = base64encoder.encode(encryptedText); }
catch (Exception e) {
e.printStackTrace(); }
return encryptedString; }
public String decrypt(String encryptedString) {
String decryptedText=null;
try {
cipher.init(Cipher.DECRYPT_MODE, key);
BASE64Decoder base64decoder = new BASE64Decoder();
byte[] encryptedText = base64decoder.decodeBuffer(encryptedString);
byte[] plainText = cipher.doFinal(encryptedText);
decryptedText= bytes2String(plainText); }
catch (Exception e) {
e.printStackTrace(); }
return decryptedText; }
private static String bytes2String(byte[] bytes) {
StringBuffer stringBuffer = new StringBuffer();

for (int i = 0; i <bytes.length; i++) {


stringBuffer.append((char) bytes[i]); }
return stringBuffer.toString(); }
public static void main(String args []) throws Exception {
System.out.print("Enter the string: ");
DES myEncryptor= new DES();
String stringToEncrypt = br.readLine();
String encrypted = myEncryptor.encrypt(stringToEncrypt);
String decrypted = myEncryptor.decrypt(encrypted);
System.out.println("\nString To Encrypt: " +stringToEncrypt);
System.out.println("\nEncrypted Value : " +encrypted);
System.out.println("\nDecrypted Value : " +decrypted);
System.out.println("");
}
}
OUTPUT
Enter the string: COMETOCOLLEGE
String to Encrypt: COMETOCOLLEGE
Encrypted Value: tQGd681pgY6vp0SYDOBfzg= =
Decrypted Value: COMETOCOLLEGE

RESULT
Thus java program to implement DES was written, executed and output is verified
successfully.

Ex.No: 7

IMPLEMENTATION OF RSA

AIM

To write a Java Program for implementing RSA.

ALGORITHM
Step 1: Start the program.
Step 2: Define a default constructor RSA to compare 2 prime numbers.
Step 3: Define a parameterized constructor to assign values.
Step 4: Define bytetostring() to convert byte to string.
Step 5: Define encrypt() to encrypt the text and decrypt() to reproduce the plain text.
Step 6: Define main() to call the encrypt() and decrypt() to perform respective
operations and display the results.
Step 7: Stop the program.

PROGRAM: /*RSA.Java*/
import java.io.*;
import java.util.*;
class RSA
{
public static void main(String args[])
{
Scanner ip=new Scanner(System.in);
int p,q,n,e=1,j;
int d=1,i1;
int t1,t2;
int pt[]= new int[10];
int ct[]= new int[10];
int rt[]= new int[10];
String i=new String();
System.out.println("Enter the two prime numbers:");
p=ip.nextInt();

q=ip.nextInt();
System.out.println("Enter the message to be sent");
i=ip.next();
i1=i.length();
for(j=0;j<i1;j++)
{
pt[j]=(i.charAt(j))-96;
}
n=p*q;
t1=p-1;
t2=q-1;
while((t1*t2)%e==0)
{
e++;
}
for(j=0;j<i1;j++)
{
ct[j]=((int)Math.pow(pt[j],e))%n;
}
System.out.println("Sender Side:");
System.out.println("----------------------");
System.out.println("Public Key(e)= "+e);
for(j=0;j<i1;j++)
{
System.out.println("Cipher Text= "+ct[j]);
}
System.out.println("Receiver Side:");
System.out.println("----------------------");
while((d*e)%(t1*t2)!=1)
{
d++;
}
System.out.println("Private Key(d)= "+d);
for(j=0;j<i1;j++)

{
rt[j]=((int)Math.pow(ct[j],d))%n;
System.out.println("Plain Text= "+rt[j]);
}
System.out.print("Decrypted Message:");
for(j=0;j<i1;j++)
{
rt[j]=rt[j]+96;
System.out.print((char)rt[j]);
} }}

OUTPUT
Enter the Two prime numbers: 5

Enter the Message to be sent: abcdef


Sender side
Public Key=3
Cipher text=1
Cipher text=8
Cipher text=12
Cipher text=4
Cipher text=5
Cipher text=6
Receiver Side
Private Key =3
Plain Text=1
Plain Text=2
Plain Text=3
Plain Text=4
Plain Text=5
Plain Text=6
Decrypted Text= abcdef
RESULT
Thus java program to implement RSA was written, executed and output is verified
successfully.

Ex.No:8

IMPLEMENTATION OF DIFFIEE - HELLMAN

AIM
To write a Java Program for implementing Diffiee - Hellman.

ALGORITHM
Step 1: Start the program.
Step 2: Define class DiffeHellman BigInt, in that main() get the details and pass the
secret key.
Step 3: Enter prime number q
Step 4: Enter primitive root element
Step 5: Enter value for x and y for private key and calculate public key
Step 6: Calculate the keys and display it.
Step 7: Stop the program.

PROGRAM /* Diffie.java*/
import java.io.*;
import java.math.BigInteger;
class Diffie
{
public static void main(String[]args)throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter prime number:");
BigInteger p=new BigInteger(br.readLine());
System.out.print("Enter primitive root of "+p+":");
BigInteger g=new BigInteger(br.readLine());
System.out.println("Enter value for x less than "+p+":");
BigInteger x=new BigInteger(br.readLine());
BigInteger R1=g.modPow(x,p);
System.out.println("R1="+R1);
System.out.print("Enter value for y less than "+p+":");
BigInteger y=new BigInteger(br.readLine());
BigInteger R2=g.modPow(y,p);

System.out.println("R2="+R2);
BigInteger k1=R2.modPow(x,p);
System.out.println("Key calculated at Alice's side:"+k1);
BigInteger k2=R1.modPow(y,p);
System.out.println("Key calculated at Bob's side:"+k2);
System.out.println("deffie hellman secret key Encryption has Taken");
}
}

OUTPUT

Enter prime number: 11


Enter primitive root of 11: 7
Enter value for x less than 11: 3
R1=2
Enter value for y less than 11:6
R2=4
Key calculated at Alice's side:9
Key calculated at Bob's side:9
deffie hellman secret key Encryption has Taken

RESULT
Thus java program to implement Diffiee Hellman was written, executed and output is verified
successfully.

Ex.No: 9

IMPLEMENTATION OF MD5

AIM
To write a Java Program for implementing MD5.

ALGORITHM
Step 1: Start the program.
Step 2: Define a class JavaMD5Hash, in that define a function MD5 to find the hash
values of three different inputs.
Step 3: Display the hash values.
Step 4: Stop the program.
PROGRAM /*MD5.java*/
import java.security.*;
public class MD5 {
public static void main(String[] a) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
System.out.println("Message digest object info: ");
System.out.println(" Algorithm = " +md.getAlgorithm());
System.out.println(" Provider = " +md.getProvider());
System.out.println(" ToString = " +md.toString());
String input = "";
md.update(input.getBytes());
byte[] output = md.digest();
System.out.println();
System.out.println("MD5(\""+input+"\") = " +bytesToHex(output));
input = "abc";
md.update(input.getBytes());
output = md.digest();
System.out.println();
System.out.println("MD5(\""+input+"\") = " +bytesToHex(output));
input = "abcdefghijklmnopqrstuvwxyz";
md.update(input.getBytes());
output = md.digest();

System.out.println();
System.out.println("MD5(\"" +input+"\") = " +bytesToHex(output));
System.out.println("");
}
catch (Exception e) {
System.out.println("Exception: " +e); }
}
public static String bytesToHex(byte[] b) {
char hexDigit[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
StringBuffer buf = new StringBuffer();
for (int j=0; j<b.length; j++) {
buf.append(hexDigit[(b[j] >> 4) & 0x0f]);
buf.append(hexDigit[b[j] & 0x0f]); }
return buf.toString(); } }

OUTPUT:
MESSAGE DIGEST OBJECT INFO:
ALGORITHM = MD5
PROVIDER = SUN VERSION 1.8
TOSTRING= MD5 MESSAGE DIGEST FROM SUN<INITIALIZED>
MD5< > = D41D8CD98F00B204E9800998ECEF8427E
MD5<ABC> = 900150983CD24FB0D6963F7D28E17F72
MD5< ABCDEFGHIJKLMNOPQRSTUVWXYZ > =
C3FCDD76192E4007DFB496CCA67E13B

RESULT
Thus java program to implement MD5 was written, executed and output is verified
successfully.

Ex.No: 10

IMPLEMENTATION OF SHA-1

AIM
To write a Java Program for implementing SHA-1.

ALGORITHM
Step 1: Start the program.
Step 2: Define a class HashTextTest, in that main() call sha1() to display secured hash
value.
Step 3: Define sha1(), in that define the instances and generate the hash value.
Step 4: Stop the program.
PROGRAM /*SHA1.java*/
import java.security.*;
public class SHA1 {
public static void main(String[] a) {
try {
MessageDigest md = MessageDigest.getInstance("SHA1");
System.out.println("Message digest object info: ");
System.out.println(" Algorithm = " +md.getAlgorithm());
System.out.println(" Provider = " +md.getProvider());
System.out.println(" ToString = " +md.toString());
String input = "";
md.update(input.getBytes());
byte[] output = md.digest();
System.out.println();
System.out.println("SHA1(\""+input+"\") = " +bytesToHex(output));
input = "abc";
md.update(input.getBytes());
output = md.digest();
System.out.println();
System.out.println("SHA1(\""+input+"\") = " +bytesToHex(output));
input = "abcdefghijklmnopqrstuvwxyz";
md.update(input.getBytes());
output = md.digest();

System.out.println();
System.out.println("SHA1(\"" +input+"\") = " +bytesToHex(output));
System.out.println(""); }
catch (Exception e) {
System.out.println("Exception: " +e);
}
}
public static String bytesToHex(byte[] b) {
char hexDigit[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
StringBuffer buf = new StringBuffer();
for (int j=0; j<b.length; j++) {
buf.append(hexDigit[(b[j] >> 4) & 0x0f]);
buf.append(hexDigit[b[j] & 0x0f]); }
return buf.toString(); }
}
OUTPUT

MESSAGE DIGEST OBJECT INFO:


ALGORITHM = SHA1
PROVIDER = SUN VERSION 1.8
TOSTRING= SHA1 MESSAGE DIGEST FROM SUN<INITIALIZED>
SHA1< > =DA39A3EE5E6B4B0D3255BFEF95601890AFD80709
SHA1<ABC> = A9993E364706816ABA3E25717850C26C9CD0D89D
SHA1<

ABCDEFGHIJKLMNOPQRSTUVWXYZ>=

32D10C7B8CF96570CA04CE37F2A19D84240D3A89

RESULT
Thus java program to implement SHA was written, executed and output is verified
successfully.

Ex.No: 11 IMPLEMENTATION OF SIGNATURE SCHEME DIGITAL SIGNATURE


STANDARD
AIM
To implement Signature Scheme of Digital Signature Standard using java.

ALGORITHM
Step 1: Start the program.
Step 2: Define a class DSS, in that define a main().
Step 3: Create instance for KeypairGenerator class.
Step 4: Generate Key Pair using KeyPair Class.
Step 5: Send the data to encrypt and sign.
Step 6: Sign the data using Signature class.
Step 7: Display the signature and verification status.
Step 8: Stop the program.
PROGRAM /* DSAKeyGen.java*/
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.PublicKey;
public class DSAKeyGen {
public static void main(String[] argv) throws Exception {
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA");
keyGen.initialize(1024);
KeyPair keypair = keyGen.genKeyPair();
PrivateKey privateKey = keypair.getPrivate();
System.out.println(privateKey);
PublicKey publicKey = keypair.getPublic();
System.out.println(publicKey);
}
}

OUTPUT

RESULT
Thus java program to implement Signature Scheme of Digital Signature Standard was
written, executed and output is verified successfully.

Ex.No: 12

CREATION OF DIGITAL SIGNATURE, SECURE DATA STORAGE,


SECURE DATA TRANSMISSION USING GNUPG

AIM
To create Digital Signature, secure Data Storage & transmission using GnuPG.

PROCEDURE

GENERATING KEYPAIR
Step 1: Open up Kleopatra.
Step 2: Go to File, then New Certificate

Step 3: The Certificate Creation Wizard should pop up, click on Create a personal OpenPGP
key pair

Step 4: Now youll enter your details. Use your marketplace username as Name, and fill out
the rest with whatever you want. You dont need to use a real email. Check the picture for an
example on how it should look.

Step 5: Click Advanced Settings, and another window should appear. Under Key
Material, make sure RSA is checked. In the drop down menu beside it, and select 4,096
bits. Check the picture to confirm you have everything set correctly, then click Ok

Step 6: Confirm you filled out all of your info correctly, then click Create Key

Step 7: Another window will pop up asking to enter a passphrase. Do so, then click Ok

Step 8: It will now generate your key. It will need you to do random things to create entropy.
Mash keys, wiggle the mouse, watch porn, download torrents, whatever

Step 9: Your key is now created. Go ahead and click Finish

OBTAINING YOUR PUBLIC KEY


Step 1: Right click on your key, then click Export Certificates

Step 2: Browse where you want to save, give it a name, then click Save

Step 3: Open your favourite text editor, browse to where the file is saved. You may have to
select All files from the dropdown menu. Click the file you saved, then open

OBTAINING PRIVATE KEY


Step 1: Right click on your key, select Export Secret Keys

Step 2: Select where you want it saved, give it a name, check ASCII armor, and click Ok

Step 3: You now have your private key

IMPORTING A PUBLIC KEY


Step 1: Find a public key you want to import.
Step 2: Copy everything from BEGIN PGP PUBLIC KEY BLOCK to END
PGP PUBLIC KEY BLOCK

Step 3: In your task bar, right click on the Kleopatra icon, go to Clipboard, then click
Certificate Import
Step 4: If it worked, you should see a window pop up, click Ok.

IMPORTING YOUR PRIVATE KEY


Step 1: Go to File, then click Import Certificates

Step 2: Browse to where your private key is, select it, then click Open

Step 3: It will import your private key, and pop up a window to confirm. Click Ok

Step 4: You should now see your key information under the My Certificates tab

ENCRYPTING A MESSAGE
Step 1: Open up your text editor of choice.
Step 2: Type out your message, select it all, and copy it.

Step 3: In your task bar, right click on the Kleopatra icon, go to Clipboard, then click
Encrypt

Step 4: window will open. Click Add Recipient

Step 5: Another window will appear. Click the Other Certificates tab, then select who you
want to send your message to, then click Ok.

Step 6: You should be back at the previous window with the recipient listed. Click Next

Step 7: If all went well, you should see this window. Click Ok

Step 8: Your encrypted message will be in your clipboard, all you need to do is paste it into
the message box and send

DECRYPTING A MESSAGE

Step 1: Copy everything that was sent.

Step 2: In your task bar, right click on the Kleopatra icon, go to Clipboard, then click
Decrypt/Verify

Step 3: A window will pop up asking for your passphrase, enter that then click Ok.

RESULT
Thus creation of Digital Signature, secure data storage and transmission was done using
Kleopatra Tool using GnuPG was done and output is verified successfully.

Ex.No: 13

SETUP A HONEY POT AND MONITOR THE HONEYPOT ON


NETWORK USING KF SENSOR

AIM
To setup a honey pot and monitor the honey pot on network using KF Sensor.

PROCEDURE
Honey Pot is a device placed on Computer Network specifically designed to capture
malicious network traffic.
KF Sensor is the tool to setup as honeypot when KF Sensor is running it places a siren icon in
the windows system tray in the bottom right of the screen. If there are no alerts then green
icon is displayed.

RESULT
Thus honey pot was set up and monitored on network using KF Sensor done successfully.

Ex.No: 14 INSTALLATION OF ROOTKITS AND STUDY ABOUT THE VARIETY


OF OPTIONS

AIM
To install rootkits and study about the variety of options.
PROCEDURE
Rootkit is a stealth type of malicious software designed to hide the existence of certain
process from normal methods of detection and enables continued privileged access to a
computer.
Step 1: Download Rootkit Tool from GMER website. www.gmer.net
Step 2: This displays the Processes, Modules, Services, Files, Registry,
RootKit/Malwares, Autostart, CMD of local host.
Step 3: Select Processes menu and kill any unwanted process if any.
Step 4: Modules menu displays the various system files like .sys, .dll
Step 5: Services menu displays the complete services running with Autostart, Enable,
Disable, System, Boot.
Step 6: Files menu displays full files on Hard-Disk volumes.
Step 7: Registry displays Hkey_Current_user and Hkey_Local_Machine.
Step 8: Rootkits/Malawares scans the local drives selected.
Step 9: Autostart displays the registry base Autostart applications.
Step 10: CMD allows the user to interact with command line utilities or Registry.

RESULT
Thus Rootkit was installed and various options were studied successfully.

Ex.No:15

PERFORM WIRELESS AUDIT ON AN ACCESS POINT OR A

ROUTER AND DECRYPT WEP AND WPA USING NET STUMBLER

AIM
To perform wireless audit on an access point or a router and decrypt WEP and WPA using
Net Stumbler.

PROCEDURE
NetStumbler (Network Stumbler) is one of the Wi-Fi hacking tool which only compatible
with windows, this tool also a freeware. With this program, we can search for wireless
network which open and infiltrate the network. Its having some compatibility and network
adapter issues.

Step 1: Download and install Netstumbler


Step 2: It is highly recommended that your PC should have wireless network card in order to
access wireless router.
Step 3: Now Run Netstumbler in record mode and configure wireless card.
Step 4: There are several indicators regarding the strength of the signal, such as GREEN
indicates Strong, YELLOW and other color indicates a weaker signal, RED indicates a very
weak and GREY indicates a signal loss.
Step 5: Lock symbol with GREEN bubble indicates the Access point has encryption enabled.
Step 6: MAC assigned to Wireless Access Point is displayed on right hand pane.
Step 7: The next coloumn displays the Access points Service Set Identifier[SSID] which is
useful to crack the password.
Step 8: To decrypt use WireShark tool by selecting Edit -> preferences ->IEEE 802.11.
Step 9: Enter the WEP keys as a string of hexadecimal numbers as A1B2C3D4E5.
Step 10: Stop the tool.

Adding Keys: Wireless Toolbar


If you are using the Windows version of Wireshark and you have an AirPcap adapter you can
add decryption keys using the wireless toolbar. If the toolbar isn't visible, you can show it by
selecting View->Wireless Toolbar. Click on the Decryption Keys... button on the toolbar:

This will open the decryption key management window. As shown in the window you can
select between three decryption modes: None, Wire shark, and Driver:

RESULT
Thus wireless audit on an access point or a router was performed and decrypted WEP and
WPA using Net Stumbler done successfully.

Ex.No: 16

DEMONSTRATE INTRUSION DETECTION SYSTEM (IDS) USING


SNORT

AIM
To demonstrate intrusion detection system (ids) using snort.

PROCEDURE
SNORT can be configured to run in three modes:
1. Sniffer mode
2. Packet Logger mode
3. Network Intrusion Detection System mode
Sniffer modesnort v Print out the TCP/IP packets header on the screen
Snort vd show the TCP/IP ICMP header with application data in transit.
Packet Logger modesnort dev l c:\log [create this directory in the C drive] and snort will
automatically know to go into packet logger mode, it collects every packet it sees and places
it in log directory. snort dev l c:\log h ipaddress/24 This rule tells snort that you want to
print out the data link and TCP/IP headers as well as application data into the log directory.
snort l c:\log b This is binary mode logs everything into a single file.
Network Intrusion Detection System modesnort d c:\log h ipaddress/24 c snort.conf This is a configuration file applies rule to each packet to decide it an action based upon the
rule type in the file. Snort d h ipaddress/24 l c:\log c snort.conf - This will configure
snort to run in its most basic NIDS form, logging packets that trigger rules specifies in the
snort.conf.

Step 1: Download SNORT from snort.org


Step 2: Install snort with or without database support.

Step 3: Select all the components and Click Next.


Step 4: Install and Close.
Step 5: Skip the WinPcap driver installation
Step 6; Add the path variable in windows environment variable by selecting new classpath.
Step 7: Create a path variable and point it at snort.exe variable namepath and variable
valuec:\snort\bin.

Step 8: Click OK button and then close all dialog boxes.


Step 9: Open command prompt and type the following commands:

C:\Snort\bin>Snort - v

C:\Snort\bin>Snort vd

RESULT
Thus Intrusion Detection System was demonstrated using Snort tool successfully.

CONTENT BEYOND SYLLABUS


IMPLEMENTATION OF MESSAGE AUTHENTICATION CODES

AIM
To implement Message Authentication Codes using Java.

ALGORITHM
Step 1: Start the program.
Step 2: Define a class SimpleMacExample, in that define GetPlainText() to get the
original text.
Step 3: Define main() to generate MAC code for the text.
Step 4: display the MAC code.
Step 5: Stop the program.

PROGRAM
package javaapplication1;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.crypto.*;
public class SimpleMacExample
{
public static String getPlainText()
{
System.out.print("Enter plaintext:");
String plaintext = "";
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try
{
plaintext = br.readLine();
}
catch (IOException ioe)
{
System.out.println("IO error trying to read plaintext!");

System.exit(1);
}

// catch

return plaintext;
}

// getPlainText()

public static void main(String[] args) throws Exception


{
System.out.println("This program generates a message authentication code for the plaintext
you enter.");
String plaintextString = getPlainText();
byte[] plaintext = plaintextString.getBytes();
KeyGenerator keygen = KeyGenerator.getInstance("HmacMD5");
SecretKey sKey = keygen.generateKey();
Mac theMac = Mac.getInstance("HmacMD5");
theMac.init(sKey);
byte[] theMacCode = theMac.doFinal(plaintext);
System.out.print("The MAC for the plaintext \'" + plaintextString + "\' is ");
for (int i = 0; i < theMacCode.length; i++)
{
System.out.print(theMacCode[i]);
if (i != theMacCode.length - 1)
{
System.out.print(",");
}
}

// if
// for i

System.out.println();
}
}

// main
// class SimpleMacExample

RESULT
Thus MAC was implemented using java and output is verified successfully.

IMPLMENTATION OF AES

AIM :To implement AES using java.

ALGORITHM
Step 1: Start the program.
Step 2: Define a class AES, in that assign values to plaintext, IV and key variables.
Step 3: Define main() to display the encrypted and decrypted text of plain text.
Step 4: Define encrypt() to generated cipher text and decrypt() to generate plain text.
Step 5: Stop the program.

PROGRAM
package javaapplication1;
import java.security.MessageDigest;
import java.util.Arrays;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import javax.crypto.spec.IvParameterSpec;

import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

public class AES


{
static String IV = "AAAAAAAAAAAAAAAA";
static String plaintext = "test text 123\0\0\0"; /*Note null padding*/
static String encryptionKey = "0123456789abcdef";
public static void main(String [] args)
{
try
{
System.out.println("==Java==");

System.out.println("plain: " + plaintext);


byte[] cipher = encrypt(plaintext, encryptionKey);
System.out.print("cipher: ");
for (int i=0; i<cipher.length; i++)
System.out.print(new Integer(cipher[i])+" ");
System.out.println("");
String decrypted = decrypt(cipher, encryptionKey);
System.out.println("decrypt: " + decrypted);
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static byte[] encrypt(String plainText, String encryptionKey) throws Exception
{
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding", "SunJCE");
SecretKeySpec key = new SecretKeySpec(encryptionKey.getBytes("UTF-8"), "AES");
cipher.init(Cipher.ENCRYPT_MODE, key,new IvParameterSpec(IV.getBytes("UTF-8")));
return cipher.doFinal(plainText.getBytes("UTF-8"));
}
public static String decrypt(byte[] cipherText, String encryptionKey) throws Exception
{
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding", "SunJCE");
SecretKeySpec key = new SecretKeySpec(encryptionKey.getBytes("UTF-8"), "AES");
cipher.init(Cipher.DECRYPT_MODE, key,new IvParameterSpec(IV.getBytes("UTF-8")));
return new String(cipher.doFinal(cipherText),"UTF-8");
}
}

RESULT
Thus AES was implemented using java and output is verified successfully.

Вам также может понравиться