Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Security
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Ron McLeod
Jeanne Boyarsky
Sheriffs:
Paul Clapham
Saloon Keepers:
Tim Holloway
Roland Mueller
Bartenders:
Forum:
Security
padding problem with AES(help)
smart mody
Greenhorn
Posts: 1
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
hello
i had problem with this code when i decrypt the text
import java.security.*; import javax.crypto.*; import javax.crypto.spec.*; import java.io.*; import java.awt.event.*; import javax.swing.*; import java.awt.*; public class AES extends JFrame { JTextArea jtfEncrypt,jtfDecrypt; JButton Encrypt,Decrypt,clear,exit; private class ClickListener implements ActionListener { public void actionPerformed(ActionEvent e) { if (e.getSource() == Encrypt) { try { Enc(); } catch (Exception ex) { ex.printStackTrace(); } ///////////// } else if (e.getSource() == Decrypt) { try { Dec(); } catch (Exception ex) { ex.printStackTrace(); } } else if (e.getSource() == clear) { Clr(); } else if (e.getSource() == exit) { System.exit(0); } } } private class Closer implements WindowListener { public void windowClosing(WindowEvent e) { ///////// } public void windowActivated(WindowEvent e) {} public void windowClosed(WindowEvent e) {} public void windowDeactivated(WindowEvent e) {} public void windowDeiconified(WindowEvent e) {} public void windowIconified(WindowEvent e) {} public void windowOpened(WindowEvent e) {} } public AES() { jtfEncrypt=new JTextArea(); jtfDecrypt=new JTextArea(); Encrypt=new JButton("Encrypt"); Decrypt=new JButton("Decrypt"); clear=new JButton("clear"); exit=new JButton("exit"); JPanel panel =new JPanel(); panel= (JPanel) getContentPane(); panel.setLayout(new GridLayout(3,1)); panel.add(jtfEncrypt); panel.add(Encrypt); panel.add(jtfDecrypt); panel.add(Decrypt); panel.add(clear); panel.add(exit); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setTitle("AES ..."); this.setResizable(false); this.setSize(500,500); this.setLocation(350,350); this.show(); ClickListener cl = new ClickListener(); Encrypt.addActionListener(cl); Decrypt.addActionListener(cl); clear.addActionListener(cl); exit.addActionListener(cl); this.addWindowListener(new Closer());//register Win(Frame) } public static String asHex (byte buf[]) { StringBuffer strbuf = new StringBuffer(buf.length * 2); int i; for (i = 0; i < buf.length; i++) { if (((int) buf[i] & 0xff) < 0x10) strbuf.append("0"); strbuf.append(Long.toString((int) buf[i] & 0xff, 16)); } return strbuf.toString(); } public static void main(String[] args) throws Exception { skeySpec = generateKey(); new AES(); } public static SecretKeySpec generateKey ( ) throws Exception { // Get the KeyGenerator KeyGenerator kgen = KeyGenerator.getInstance("AES"); kgen.init(128); // 192 and 256 bits may not be available // Generate the secret key specs. SecretKey skey = kgen.generateKey(); byte[] raw = skey.getEncoded(); SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); return skeySpec ; } public void Enc () throws Exception { // Instantiate the cipher Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.ENCRYPT_MODE, skeySpec); byte[] encrypted =cipher.doFinal(jtfEncrypt.getText().trim().getBytes()); jtfDecrypt.setText(asHex(encrypted)); } public void Dec () throws Exception { Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, skeySpec); byte[] decrypted =cipher.doFinal(jtfDecrypt.getText().trim().getBytes()); jtfEncrypt.setText(asHex(decrypted)); } public void Clr () { jtfDecrypt.setText(""); jtfEncrypt.setText(""); } private static SecretKeySpec skeySpec ; }
please i want the solution please
I'm doing laundry! Look how clean this tiny ad is:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
How to use AES DECRYPT_MODE?
AES decryption - InvalidKeyException: Parameters missing
AES Encryption/Decrypton
Trouble encrypting correctly with AES with a static key
AES Encryption
More...