Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 17th, 2012, 10:48 PM
Cobra800089 Cobra800089 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 1 Cobra800089 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 30 sec
Reputation Power: 0
Encryption/Decryption Issue

Hello everyone,

I'm trying to take an existing client/server chat client and encrypt the information before it goes across (This is working fine) and decrypt it when it comes in. (Here in lies the issue)

The exact problem occurs at the line:
Code:
ptLength += cipher.doFinal(plainText, outputSize);


It is a problem with the "doFinal" function and no matter what I do it always throws the exception. I've even tried hard coding in the buffer length (the second argument in doFinal) to the correct size, and this still doesn't work. I'm completely stumped and I'm getting quite frustrated. Have been troubleshooting this for HOURS.

Here is the entire readLine while loop:

Code:
String s;
        while ((s = in.readLine()) != null)
		{
			try
			{
				//Beginning of the AES Decryption process
				byte[] input = s.getBytes();
				byte[] cipherText = new byte[input.length];
				SecretKeySpec key = new SecretKeySpec(keyBytes, "AES");
				Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding", "BC");
				int ctLength = s.length();
				byte[] plainText = new byte[ctLength];
				
				cipher.init(Cipher.DECRYPT_MODE, key);
				
				int ptLength = cipher.update(cipherText, 0, ctLength, plainText, 0);
				int outputSize = cipher.getOutputSize((ctLength/16 + 1) * 16);
				
				ptLength += cipher.doFinal(plainText, outputSize);
				/*
				System.out.println("plain text : " + new String(plainText) + " bytes: " + ptLength);
				
				//End of the AES Decryption process
				
				String encryptedText = new String(cipherText);
				enteredText.setText(encryptedText + "\n");
			
				enteredText.insert(new String(plainText) + "\n", new String(plainText).length());
				enteredText.setCaretPosition(new String(plainText).length());
				*/
				
			}
			catch (Exception ace)
			{
				enteredText.setText("Error during AES Decryption process");
			}
        }



I will upload the entire program if need be, although it's rather large and in many different files.

I appreciate any help

Thank you,
Jordan

Reply With Quote
  #2  
Old December 18th, 2012, 01:55 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 2,958 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 3 h 7 m 10 sec
Reputation Power: 345
Quote:
it always throws the exception

Can you post the full text of the exception?

Does the technique and methods you are using work in a small standalone program without the client/server features?

Have you printed out the bytes that were sent and the bytes that are received and compared them to make sure they are identical?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Encryption/Decryption Issue

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap