3DES with ECB mode example in Java
D3ESECB.java
package bsr;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
class D3ESECB
{
public KeyGenerator keygenerator;
public SecretKey myDesKey;
Cipher c;
public D3ESECB() throws Exception
{
// Genrate the Key
keygenerator = KeyGenerator.getInstance("DESede");
myDesKey = keygenerator.generateKey();
// Create the cipher
c = Cipher.getInstance("DESede/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);
return(textEncrypted);
}
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));
}
}
D3ES.java
import bsr.*;
public class D3ES
{
public static void main(String[] argv) throws Exception
{
D3ESECB d=new D3ESECB();
String str=d.doEncryption("BipinRupadiya");;
System.out.println("Encrypted String : "+str);
System.out.println("Encrypted String : "+d.doDecryption(str));
}
}
public class D3ES
{
public static void main(String[] argv) throws Exception
{
D3ESECB d=new D3ESECB();
String 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 D3ES.java
- execute D3ES.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.
1 comments:
Can please give one example for 3Des with ECB using private key?
Post a Comment