DES with CFM mode example in Java
DESCFM.java
class DESCFM
{
public KeyGenerator keygenerator;
public SecretKey myDesKey;
Cipher c;
public IvParameterSpec iv;
public DESCFM() throws Exception
{
// Genrate the Key
keygenerator = KeyGenerator.getInstance("DES");
keygenerator.init(new SecureRandom());
myDesKey = keygenerator.generateKey();
// Create the cipher
c = Cipher.getInstance("DES/CFB/PKCS5Padding");
iv = new IvParameterSpec(new byte[8]);
}
public byte[] doEncryption(String s) throws Exception
{
// Initialize the cipher for encryption
c.init(Cipher.ENCRYPT_MODE, myDesKey,iv);
//sensitive information
byte[] text = s.getBytes();
// Encrypt the text
byte[] textEncrypted = c.doFinal(text);
return(textEncrypted);
}
public String doDecryption(byte[] s)throws Exception
{
// Initialize the same cipher for decryption
c.init(Cipher.DECRYPT_MODE, myDesKey,iv);
// Decrypt the text
byte[] textDecrypted = c.doFinal(s);
return(new String(textDecrypted));
}
}
{
public KeyGenerator keygenerator;
public SecretKey myDesKey;
Cipher c;
public IvParameterSpec iv;
public DESCFM() throws Exception
{
// Genrate the Key
keygenerator = KeyGenerator.getInstance("DES");
keygenerator.init(new SecureRandom());
myDesKey = keygenerator.generateKey();
// Create the cipher
c = Cipher.getInstance("DES/CFB/PKCS5Padding");
iv = new IvParameterSpec(new byte[8]);
}
public byte[] doEncryption(String s) throws Exception
{
// Initialize the cipher for encryption
c.init(Cipher.ENCRYPT_MODE, myDesKey,iv);
//sensitive information
byte[] text = s.getBytes();
// Encrypt the text
byte[] textEncrypted = c.doFinal(text);
return(textEncrypted);
}
public String doDecryption(byte[] s)throws Exception
{
// Initialize the same cipher for decryption
c.init(Cipher.DECRYPT_MODE, myDesKey,iv);
// Decrypt the text
byte[] textDecrypted = c.doFinal(s);
return(new String(textDecrypted));
}
}
DES.java
import bsr.*;
/*A code from www.bipinrupadiya.com*/
public class DES
{
public static void main(String[] argv) throws Exception
{
DESCFM d=new DESCFM();
byte[] str=d.doEncryption("BipinRupadiya");
System.out.println("Encrypted String : "+str);
System.out.println("Encrypted String : "+d.doDecryption(str));
}
}
/*A code from www.bipinrupadiya.com*/
public class DES
{
public static void main(String[] argv) throws Exception
{
DESCFM d=new DESCFM();
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 DES.java
- execute DES.java
Subscribe to:
Post Comments (Atom)
Subjects
- WordPress
- Mobile Computing-4649303 Practical Solution
- Android Programming New Syllabus Theory
- PHP LAMP Question Bank
- PHP LAMP Theory
- Step by Step Android Example
- Android Practical
- Android Theory
- Android Question Bank
- Networking FON Practical
- Networking FON Theory
- OS Practical
- OS Theory
- HTML
- JavaScript
- J2EE WTAD Theory
- J2EE WTAD Question Bank
- J2EE WTAD Quick Guide
- J2EE WTAD GTU Papers
- J2EE WTAD Practical
- Python
- JAVA Theory
- JAVA Practical
- MIS
Categories
- Android (55)
- c (11)
- Configure Tomcat7 (2)
- CSS (3)
- Decryption (16)
- Difference (1)
- Encryption (16)
- Error Detection and Correction Techniques (3)
- FON (27)
- Framing Technic (2)
- install Tomcat (2)
- J2EE (29)
- JAVA (13)
- JavaScript (19)
- linux (8)
- OS (17)
- PHP (11)
- Protocol (3)
- SERVER SOCKET PROGRAMING (7)
- Servlet (13)
- shell script (33)
- unix (22)
- WTAD (34)
Blog Archive
-
▼
2013
(64)
-
▼
June
(25)
- Example of command line argument in C on Linux
- Example of command line argument in Java
- AES with CBC mode example in Java
- AES with CFM mode example in Java
- AES with ECB mode example in Java
- 3DES with CFM mode example in Java
- 3DES with CBC mode example in Java
- 3DES with ECB mode example in Java
- RSA Encryption Example in Java
- JSP JDBC Example
- example of preparedstatement in java
- example of page directive in jsp
- example of jsp scripting elements
- Example of requestdispatcher
- JSTL standard tag library Example
- DES with CBC mode example in Java
- DES with CFM mode example in Java
- DES with ECB mode example in Java
- One Time Pad Encryption Example using Java code
- S-Box Example using Java
- P-Box Example using Java
- Transposition cipher example using Java
- Mono-alphabetic Substitution Cipher example using ...
- Generalized Caesar Cipher example using java
- java socket programming example
-
▼
June
(25)
Total Pageviews
© BipinRupadiya.com. Powered by Blogger.
0 comments:
Post a Comment