Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #7457

Re: Using encryption with special Unicode characters

Date 2011-08-29 00:29 -0700
From Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com>
Newsgroups comp.lang.java.programmer
Subject Re: Using encryption with special Unicode characters
References <OvWdnUIcqeRBsMbTnZ2dnUVZ_gCdnZ2d@westnet.com.au>
Message-ID <rZKdndUngJVcosbTnZ2dnUVZ_jCdnZ2d@posted.palinacquisition> (permalink)

Show all headers | View raw


On 8/28/11 11:11 PM, Qu0ll wrote:
> This is my first go at using Java encryption. I have a requirement to
> encrypt and then later decrypt a series of strings that may contain
> special Unicode characters such as "\u25bc". The code below correctly
> encrypts and decrypts "normal" ASCII strings but turns characters like
> "\u25bc" into '?' when it decrypts (or maybe even when it encrypts).
>
> It doesn't really matter which encryption algorithm I use as long as it
> is reasonably secure (I chose AES) but the encryption/decryption process
> needs to handle these special characters.
>
> The output from the following code is:
>
> Before char(0): 9660
> After char(0): 63
> Equal: false
>
> How can I get this to work? [...]

In addition to the reply from Mayeul (which is on the mark), I would 
offer some more general debugging advice:

Your problem can be more easily deciphered if you take the important 
step of reducing the problem into its component parts.  You have two 
different transformations going on, and of course either of the 
transformations could be messing things up.

The correct first step is to test both the encryption and the character 
encoding/decoding steps separately.  You can test encryption by 
encrypting a byte array of known values (for general testing, generated 
pseudo-randomly gives you a "better" test, while even some predefined 
sequence of bytes would be a good initial test…but for this specific 
issue, the best test is simply to compare the original byte array you 
got from the string to the one you get after encrypting and then 
decrypting that original byte array).  And the character 
encoding/decoding of course can be tested by converting a string to 
bytes and then back again (specifically, one of the strings you've 
identified as being problematic).

Bottom line: your actual question is somewhat obfuscated by the 
inclusion of encryption in the question.  Encryption doesn't care about 
characters…it only deals with bytes, so it's practically certain that 
the encryption aspect is a complete red herring.  You can be more 
effective both at figuring problems out yourself, as well as at posting 
a true SSCCE and a focused question, if you get into the habit of really 
narrowing down a problem to its essential part.

Pete

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Using encryption with special Unicode characters "Qu0ll" <Qu0llSixFour@gmail.com> - 2011-08-29 16:11 +1000
  Re: Using encryption with special Unicode characters Mayeul <mayeul.marguet@free.fr> - 2011-08-29 08:56 +0200
    Re: Using encryption with special Unicode characters "Qu0ll" <Qu0llSixFour@gmail.com> - 2011-08-29 17:18 +1000
  Re: Using encryption with special Unicode characters Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-08-29 00:29 -0700
  Re: Using encryption with special Unicode characters Roedy Green <see_website@mindprod.com.invalid> - 2011-08-29 04:29 -0700

csiph-web