This week's book giveaway is in the
General Computing
forum.
We're giving away four copies of
Arduino in Action
and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See
this thread
for details.
A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
Arduino in Action
this week in the
General Computing
forum!
A special promo:
Enter your blog post or vote on a blogger to be featured in an upcoming Journal
JavaRanch
»
Java Forums
»
Engineering
»
Security
Author
AES_DECRYPT function return null
kim pham
Greenhorn
Joined: May 11, 2011
Posts: 13
posted
Oct 25, 2011 17:35:03
0
Hi all
the aes_decrypt function return null.
Anything was wrong with this aea_decrypt function.
Thanks in advance,
-K
public static String aes_encrypt16(String password) { String strKey = "abcdefghijklmnop"; try { byte[] keyBytes = Arrays.copyOf(strKey.getBytes("ASCII"), 16); SecretKeySpec key = new SecretKeySpec(keyBytes, "AES"); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.ENCRYPT_MODE, key); byte[] cleartext = password.getBytes("UTF-8"); byte[] ciphertextBytes = cipher.doFinal(cleartext); return new String(Hex.encodeHex(ciphertextBytes)); } catch (Exception ex) { ex.printStackTrace(); return null; } } public static String aes_decrypt16(String password) { String strKey = "abcdefghijklmnop"; try { byte[] keyBytes = Arrays.copyOf(strKey.getBytes("ASCII"), 16); SecretKeySpec key = new SecretKeySpec(keyBytes, "AES"); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, key); byte[] original = cipher.doFinal(password.getBytes()); return new String(original); } catch (Exception ex) { ex.printStackTrace(); return null; }
greg stark
Ranch Hand
Joined: Aug 10, 2006
Posts: 220
posted
Oct 25, 2011 20:06:15
0
You seem to be missing the hex decode step on decrypt. Are you getting an exception?
Nice to meet you.
kim pham
Greenhorn
Joined: May 11, 2011
Posts: 13
posted
Oct 28, 2011 14:39:20
0
Hi,
Didn't get the any exception? But it returns a null value.
Any suggestion?
KP
greg stark
Ranch Hand
Joined: Aug 10, 2006
Posts: 220
posted
Oct 29, 2011 10:14:45
0
kim pham wrote:
Hi,
Didn't get the any exception? But it returns a null value.
Any suggestion?
KP
I suggest you read the first 11 words of my 16 word reply.
I agree. Here's the link:
http://zeroturnaround.com/jrebel
- it saves me about five hours per week
subject: AES_DECRYPT function return null
Similar Threads
Using a one way hash for Password encryption
padding problem with AES(help)
error coming while decrypting...
Encrypted values all contain same final characters
AES decryption problem
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter