[go: up one dir, main page]

0% found this document useful (0 votes)
2 views3 pages

Security Lab Exp-3

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Security Lab Exp-3

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Ex.

No : 3 Data Encryption Standard (DES) Algorithm


Date : (User Message Encryption )

AIM:
To use Data Encryption Standard (DES) Algorithm for a practical
application like User Message Encryption.

ALGORITHM:
1. Create a DESKey.
2. Create a Cipher instance from Cipher class, specify
thefollowing information and separated by a slash(/).
a. Algorithmname
b. Mode(optional)
c. Padding scheme(optional)
3. Convert String into Byte[] arrayformat.
4. Make Cipher in encrypt mode, and encrypt it with Cipher.doFinal()method.
5. Make Cipher in decrypt mode, and decrypt it with Cipher.doFinal()method.

PROGRAM:

import javax.crypto.Cipher;
import
javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;

public class Solution {


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

KeyGenerator keyGen = KeyGenerator.getInstance("DES");


SecretKey secretKey = keyGen.generateKey();

Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");

String message = "Secret Information";

System.out.println("Message Encryption Using DES Algorithm");


byte[] plainTextBytes = message.getBytes();
System.out.println("Message [Byte Format] : " + plainTextBytes);

cipher.init(Cipher.ENCRYPT_MODE, secretKey);
byte[] encryptedBytes = cipher.doFinal(plainTextBytes);
System.out.println("Message: " + message + " Encrypted");

cipher.init(Cipher.DECRYPT_MODE, secretKey);
byte[] decryptedBytes = cipher.doFinal(encryptedBytes);
System.out.println("Message: " + encryptedBytes + " Decrypted");
System.out.println("Message: " + new String(decryptedBytes));
}
}

OUTPUT:
Message Encryption Using DES Algorithm

Message [Byte Format] :[B@4dcbadb4


Message : Secret Information Encrypted
Message: [B@504bae78 Decrypted
Message: SecretInformation

RESULT:
Thus the java program for DES Algorithm has been implemented and the output
verified successfully.

You might also like