ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alexey N. Solofnenko" <A.Solofne...@mdl.com>
Subject Re: binary data and filterchain framework [was encrypting/decrypting]
Date Tue, 20 Jun 2006 16:39:23 GMT
That is why I put a note to use hexadecimal conversion for encrypted 
strings.

  public static String asHex(byte buf[]) {
    if (buf==null)
      return null;
    StringBuffer strbuf=new StringBuffer(buf.length*2);
    for (int i=0, l=buf.length; i<l; i++) {
      int b=buf[i]&0xFF;
      if (b<0x10)
        strbuf.append('0');
      strbuf.append(Long.toString(b, 16));
    }
    return strbuf.toString();
  }

  public static byte[] fromHex(String str) {
    if (str==null)
      return null;
    final int strLen=str.length();
    byte[] buf=new byte[strLen/2];
    for (int i=0, j=0; i<strLen; i+=2, j++) {
      buf[j]= (byte)Integer.parseInt(str.substring(i, i+2), 16);
    }
    return buf;
  }


- Alexey.

Antoine Levy-Lambert wrote:
> Hey,
>
> I found something useful.
>
> The problem in the round trip binary data ===> string ===> binary data
> is that in standard western character sets, there are a lot of slots which are marked
"undefined". I had for instance a problem with 0x81 (decimal 129) which was transformed into
0x3f (question mark).
>
> I found out that the Arabic Character Set Cp1256 has all slots used, so can be used as
a vehicle to do round trips with binary data using the filterchain framework. 
>
> Regards,
>
> Antoine
>
> [1] http://www.microsoft.com/typography/unicode/1250.htm this char set has empty slots
> [2] http://www.microsoft.com/typography/unicode/1256.htm this char set has no empty slots.
>
> -------- Original-Nachricht --------
> Datum: Tue, 20 Jun 2006 09:13:49 -0400
> Von: Antoine Levy-Lambert <antoine@gmx.de>
> An: Ant Users List <user@ant.apache.org>
> Betreff: Re: Ant tasks to encrypt or decrypt passwords from property files
>
>   
>> Hello Alexey,
>>
>> I have written something based on your code.
>> Actually, I wrote an ant task to create the key first.
>> I wanted to create filters (pluggable into filterchains) to encrypt and
>> decrypt, but I do not get that to work.
>> I might do an ant task to encrypt and a sort of loadproperties clone
>> which would take an encrypted file.
>> When I use filterchains and loadproperties, the decrypting does not
>> work, some of the bytes read by loadproperties (or the filterchain
>> framework) are not the same as the original.
>> Unfortunately, I am not litterate enough with streams, bytes, binary
>> operators and the like to know how to fix this. A shame, the solution
>> with filters would be elegant.
>>
>> Regards,
>>
>> Antoine
>>
>>
>>     
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>   

Mime
View raw message