Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!

Henry Wong

author
+ Follow
since Sep 28, 2004
Henry likes ...
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
Forum Moderator
Henry Wong currently moderates these forums:
New York City
linkedin.com
Cows and Likes
Cows
Total received
142
In last 30 days
0
Total given
692
Likes
Total received
2252
Received in last 30 days
1
Total given
328
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Henry Wong


First, a big thanks to Iuliana Cosmina for being here to promote the book Pivotal Certified Professional Core Spring 5 Developer Exam: A Study Guide Using Spring Framework 5 .

The winners are:

   Raghavendra Desoju
   Thomas Buell
   Skumar Patel
   Ruan Perondi

Please send your snail mail address to bookpromotion AT javaranch DOT com. To ensure the quickest response, please provide the following:

Your name (first and last - if your CodeRanch name is different, please include both your real name and Ranch name)
Email
Country (needed even if requesting an e-book)
Address
Phone Number


Also, please include the following as the subject of your Email.

Book Promo Winner - Pivotal Certified Professional Core Spring 5 Developer Exam: A Study Guide Using Spring Framework 5  - Tuesday, June 16th, 2020


Image from https://m.media-amazon.com

As noted in the Book Promotion Eligibility Requirements and Legal type stuff, the winners have 8 days to submit their information. Within 3 days of receipt of your email, we will reply to let you know we got it. If you don't hear back, the goat might have eaten your email. Please let us know by posting in the Ranch Office so we can check on it. Once you have received your copy please let us know by editing the Book Promotions Winners Page and updating the 'Status' column to say you have it.

Thanks and congrats to all the winners.
Java 1.4 was released sometime in 2002. Java 5 (which uses 1.5 in the directory), was released sometime in 2004. Both of these versions of Java are older than you are! I don't even know where to find those versions of Java anymore.  And BTW, the current version of Java is version 14.
2 weeks ago

First, a big thanks to Veljko Krunic for being here to promote the book Succeeding with AI. How to make AI work for your business..

The winners are:

   Lucian Maly
   paul nisset
   DineshC Sharma
   Tim Holloway

Please send your snail mail address to bookpromotion AT javaranch DOT com. To ensure the quickest response, please provide the following:

Your name (first and last - if your CodeRanch name is different, please include both your real name and Ranch name)
Email
Country (needed even if requesting an e-book)
Address
Phone Number


Also, please include the following as the subject of your Email.

Book Promo Winner - Succeeding with AI. How to make AI work for your business. - Tuesday, June 2nd, 2020


Image from https://images.manning.com

As noted in the Book Promotion Eligibility Requirements and Legal type stuff, the winners have 8 days to submit their information. Within 3 days of receipt of your email, we will reply to let you know we got it. If you don't hear back, the goat might have eaten your email. Please let us know by posting in the Ranch Office so we can check on it. Once you have received your copy please let us know by editing the Book Promotions Winners Page and updating the 'Status' column to say you have it.

Thanks and congrats to all the winners.

This week, we're delighted to have Veljko Krunic helping to answer questions about the new book Succeeding with AI. How to make AI work for your business..


The promotion starts Tuesday, June 2nd, 2020 and will end on Friday, June 5th, 2020

We'll be selecting four random posters in this forum to win a free copy of the book provided by the publisher, Manning Publications.


Image from https://images.manning.com

Please see the Book Promotion page to ensure your best chances at winning!

Posts in this welcome thread are not eligible for the drawing, and should be reserved for welcoming the author. Questions posted in this topic are subject to removal.


First, a big thanks to Deepak Vohra for being here to promote the book Practical Amazon Elastic Kubernetes Service (AWS EKS).

The winners are:

   Debashish Chakrabarty
   Celso Furtado
   Ron McLeod
   Greg Horie

Please send your snail mail address to bookpromotion AT javaranch DOT com. To ensure the quickest response, please provide the following:

Your name (first and last - if your CodeRanch name is different, please include both your real name and Ranch name)
Email
Country (needed even if requesting an e-book)
Address
Phone Number


Also, please include the following as the subject of your Email.

Book Promo Winner - Practical Amazon Elastic Kubernetes Service (AWS EKS) - Tuesday, May 19th, 2020


Image from https://m.media-amazon.com

As noted in the Book Promotion Eligibility Requirements and Legal type stuff, the winners have 8 days to submit their information. Within 3 days of receipt of your email, we will reply to let you know we got it. If you don't hear back, the goat might have eaten your email. Please let us know by posting in the Ranch Office so we can check on it. Once you have received your copy please let us know by editing the Book Promotions Winners Page and updating the 'Status' column to say you have it.

Thanks and congrats to all the winners.
1 month ago

This week, we're delighted to have Deepak Vohra helping to answer questions about the new book Practical Amazon Elastic Kubernetes Service (AWS EKS).


The promotion starts Tuesday, May 19th, 2020 and will end on Friday, May 22nd, 2020

We'll be selecting four random posters in this forum to win a free copy of the book provided by the author, Deepak Vohra.


Image from https://m.media-amazon.com

Please see the Book Promotion page to ensure your best chances at winning!

Posts in this welcome thread are not eligible for the drawing, and should be reserved for welcoming the author. Questions posted in this topic are subject to removal.
1 month ago

First, a big thanks to Laura Graesser & Wah Loon Keng for being here to promote the book Foundations of Deep Reinforcement Learning.

The winners are:

   Gary W. Lucas
   Tim Holloway
   Bob Winter
   kiros haregewoine

Please send your snail mail address to bookpromotion AT javaranch DOT com. To ensure the quickest response, please provide the following:

Your name (first and last - if your CodeRanch name is different, please include both your real name and Ranch name)
Email
Country (needed even if requesting an e-book)
Address
Phone Number


Also, please include the following as the subject of your Email.

Book Promo Winner - Foundations of Deep Reinforcement Learning - Tuesday, April 28th, 2020


Image from https://m.media-amazon.com

As noted in the Book Promotion Eligibility Requirements and Legal type stuff, the winners have 8 days to submit their information. Within 3 days of receipt of your email, we will reply to let you know we got it. If you don't hear back, the goat might have eaten your email. Please let us know by posting in the Ranch Office so we can check on it. Once you have received your copy please let us know by editing the Book Promotions Winners Page and updating the 'Status' column to say you have it.

Thanks and congrats to all the winners.

This week, we're delighted to have Laura Graesser & Wah Loon Keng helping to answer questions about the new book Foundations of Deep Reinforcement Learning.


The promotion starts Tuesday, April 28th, 2020 and will end on Friday, May 1st, 2020

We'll be selecting four random posters in this forum to win a free copy of the book provided by the publisher, Addison-Wesley Professional A.


Image from https://m.media-amazon.com

Please see the Book Promotion page to ensure your best chances at winning!

Posts in this welcome thread are not eligible for the drawing, and should be reserved for welcoming the author. Questions posted in this topic are subject to removal.


First, a big thanks to Dr. Raoul-Gabriel Urma & Richard Warburton for being here to promote the book Real-World Software Development: A Project-Driven Guide to Fundamentals in Java.

The winners are:

   Al Razor
   Junilu Lacar
   Purushotham Chikkanayakanhalli Krishnegowda
   meenakshi sundar

Please send your snail mail address to bookpromotion AT javaranch DOT com. To ensure the quickest response, please provide the following:

Your name (first and last - if your CodeRanch name is different, please include both your real name and Ranch name)
Email
Country (needed even if requesting an e-book)
Address
Phone Number


Also, please include the following as the subject of your Email.

Book Promo Winner - Real-World Software Development: A Project-Driven Guide to Fundamentals in Java - Tuesday, March 31st, 2020


Image from https://m.media-amazon.com

As noted in the Book Promotion Eligibility Requirements and Legal type stuff, the winners have 8 days to submit their information. Within 3 days of receipt of your email, we will reply to let you know we got it. If you don't hear back, the goat might have eaten your email. Please let us know by posting in the Ranch Office so we can check on it. Once you have received your copy please let us know by editing the Book Promotions Winners Page and updating the 'Status' column to say you have it.

Thanks and congrats to all the winners.

This week, we're delighted to have Dr. Raoul-Gabriel Urma & Richard Warburton helping to answer questions about the new book Real-World Software Development: A Project-Driven Guide to Fundamentals in Java.


The promotion starts Tuesday, March 31st, 2020 and will end on Friday, April 3rd, 2020

We'll be selecting four random posters in this forum to win a free copy of the book provided by the publisher, O'Reilly Media.


Image from https://m.media-amazon.com

Please see the Book Promotion page to ensure your best chances at winning!

Posts in this welcome thread are not eligible for the drawing, and should be reserved for welcoming the author. Questions posted in this topic are subject to removal.

Terrance Samson wrote:
Well I know for a fact that the C# program that I'm using does not expand the data at all.  If I start with a 94,820,763 byte unencrypted file then when I encrypt it, I get a 94,820,763 byte encrypted file.  And it's using AES.



AES is not the primary encryption that I use -- so, I can't give any more information in that regard. Sorry.

Terrance Samson wrote:
Are you absolutely certain that ASCII never uses all 8 bits?  I was pretty sure that it does, but that half of the values are stuff like the Greek alphabet and other characters which aren't used as often.



There have been many extended ASCII formats over the years. Many of these are now replaced with Unicode. If this is one of the formats that you are using, there isn't much that Java can do to help. You will definitely need to use raw bytes -- and deal with all format specific stuff yourself.

Henry
3 months ago

Terrance Samson wrote:As I was afraid would happen, I printed the length of the original unencrypted string and it's 48 characters, but then when I printed the length of the toDecrypt array (which is of course encrypted) it's 64 bytes, so it's expanding by one third (I don't know why it's that amount).



Encrypted data are generally larger than their original data counterpart. This is because encrypted data also hold stuff needed to hide the original data. Additionally, many encryption algorithm purposely increases the size in a way that can't be calculated. This is because the algorithm is protecting the details of the original data -- which includes the size of the original data.

Henry  
3 months ago

Terrance Samson wrote:
But why should this be so difficult to do in Java?



To start, ASCII codes are *not* a single byte... To be exact, it is 7 bits long. And historically, most systems (that store and transfer the data) just use 8 bits (a byte), with the last bit being zero. This is because it is a lot easier to repurpose hardware and code for it, than to redevelop for 7 bits.

.... and Unicode is backward compatible with ASCII codes. Basically, all valid ASCII codes are Unicode. This is because of how Unicode is defined. Since ASCII code are 7 bits long (with the 8th bit being zero), Unicode for the ASCII range are the same. If it is valid ASCII, then it is valid Unicode. The enhancement is when the 8th bit is not zero -- when there can be more than one byte per character.

So... Java strings are Unicode *and* they are also ASCII strings. And you can't hold 8 bit data with ASCII strings (not valid ASCII anyway).

Henry
3 months ago

Terrance Samson wrote:
1: I need to test to make sure that the data is alright, so if I can read a string that makes it a lot easier.



Unfortunately, this is not possible (via directly to strings). You need to create code that can check the binary data, which may have to include a loop that displays all the information as numbers.

Terrance Samson wrote:
2: Ultimately this will be used for encrypting/decrypting text, among other things, but remember, the files that it reads/writes must be compatible with a C# program which already exists, does not use base 64, and uses ASCII strings (as far as I can tell, but ultimately it stores RTF, but I'm pretty sure it's using ASCII to store the RTF, but with formatting that can make Unicode characters as necessary).



Binary data can't really be held using ASCII. So, there is either some sort of lack of checking on the C# side, or the C# code is using some sort of encoding that is not base64. I would advise against guessing, as you can't replicate it on the Java side, if you are not sure what the C# side is doing.

EDIT: BTW, forgot to mention. If the file is in RTF format, then, your Java side needs to process that too.

Henry
3 months ago