• Post Reply Bookmark Topic Watch Topic
  • New Topic

AES Encrypter/Decrypter  RSS feed

 
Sultan Altoobi
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Every Body,,

I have a program that hides text inside image.

I want to enctrypt the text before hiding it inside the image, so

I'm looking for AES code that accepts text from JTextArea and encrypt it before hiding the text inside the image.

Also the code decrypt the ciphertext after getting it from the image.

Any HELP! please!!!
 
Tim Moores
Saloon Keeper
Posts: 4034
94
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing to do with 'Swing / AWT / SWT / JFace.' Moving to 'Beginning Java'
 
Sultan Altoobi
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Thanks alot Tim Moores.

The problem is I'm a beginner in java. I don't know much in programing with java.
I did read the code. I don't know where is the input text and how to get the cipher text.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sultan Altoobi wrote:
I did read the code, but I don't know where will be input text, and how to get the ciphertext so I can hide it inside image.


The one line in the example to look at is here...



The input text is either the test string, or the first parameter, depending on whether there is a first parameter. And the ciphertext is in the encrypted byte array.

Henry
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

And BTW, the example generates a new secret key every time. This is unlikely what you want.

More likely, you want to generate the key only once, and save it somewhere. Or simply choose the key yourself, and again, save it somewhere.

Henry
 
Sultan Altoobi
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks alot Henry.

what if I use a password in the program, so that the password itself will be
the key for AES?

I read this Idea somewhere here in the fourms, but even I need
help in how to make this modification to the code.

I'm Grateful to you if you give me from your time and help me. please!
 
Tim Moores
Saloon Keeper
Posts: 4034
94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can create your own SecretKey object from a known password using something like new SecretKeySpec("this is my secret password".getBytes(), "AES").
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sultan Altoobi wrote:
what if I use a password in the program, so that the password itself will be
the key for AES?

I read this Idea somewhere here in the fourms, but even I need
help in how to make this modification to the code.


Well, it's not that hard. An AES key is 128 bit (one option), so that's just a 16 bytes in an array. You just need to write a mechanism to convert a string into such an array.

BTW, I believe the JCE has code that does this already (by using MD5 with a password string), but I never used it, so maybe someone else can chime in here.

Henry
 
Sultan Altoobi
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tim Moores and Henry for your time and help.

I will try to do it.

Best Regards.
 
Sultan Altoobi
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Moores wrote:You can create your own SecretKey object from a known password using something like new SecretKeySpec("this is my secret password".getBytes(), "AES").


Here your way did work fine. But it is a must that the key should be 16 charecters.

So, my idea is to insert the password into MD5 and use the hash (which is 32char) as the key so it will be a strong key.
but the 256 key of AES is not working in this code.

I decided to take Half of the hash value so it will be 16char and that equals to the 128key of AES

any help how to take Half the hash please!
 
Sultan Altoobi
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Done!

This how I can get half of hash value

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!