postheadericon DES with ECB mode example in Java

import bsr.*;
import javax.crypto.*;
import javax.crypto.spec.*;
/*A code from*/
class DESECB
public KeyGenerator keygenerator;
public SecretKey myDesKey;
Cipher c;

public DESECB() throws Exception
// Genrate the Key
keygenerator = KeyGenerator.getInstance("DES");
myDesKey = keygenerator.generateKey();

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

public byte[] doEncryption(String s) throws Exception

   // Initialize the cipher for encryption
   c.init(Cipher.ENCRYPT_MODE, myDesKey);

   //sensitive information
   byte[] text = s.getBytes();

// Encrypt the text
   byte[] textEncrypted = c.doFinal(text);

public String doDecryption(byte[] s)throws Exception

   // Initialize the same cipher for decryption
   c.init(Cipher.DECRYPT_MODE, myDesKey);

   // Decrypt the text
   byte[] textDecrypted = c.doFinal(s);

return(new String(textDecrypted));

import bsr.*;
/*A code from*/
public class DES

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

byte[] str=d.doEncryption("BipinRupadiya");
System.out.println("Encrypted String : "+str);
System.out.println("Encrypted String : "+d.doDecryption(str));

To execute this code

  • open two command prompt
  • compile bsr package
  • compile
  • execute


Unknown said...

Greetings. Where can I get the bsr package?

Unknown said...

Greetings, where can I get the bsr package?

Unknown said...

sir,where can i get the bsr package ?

Blog Archive

Total Pageviews

© Powered by Blogger.