From: Aleš Křenek Date: Thu, 10 Apr 2008 08:56:55 +0000 (+0000) Subject: use base64 in the right way X-Git-Tag: glite-yaim-lb_R_4_0_2_1~109 X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=a7e13a56a69722255d8ba70d4c33412e7815560b;p=jra1mw.git use base64 in the right way --- diff --git a/org.glite.jobid.api-java/src/org/apache/commons/codec/binary/package.html b/org.glite.jobid.api-java/src/org/apache/commons/codec/binary/package.html index 71b63cd..844d918 100644 --- a/org.glite.jobid.api-java/src/org/apache/commons/codec/binary/package.html +++ b/org.glite.jobid.api-java/src/org/apache/commons/codec/binary/package.html @@ -1,20 +1,20 @@ - - - - Base64, Binary, and Hexadecimal String encoding and decoding. - - + + + + Base64, Binary, and Hexadecimal String encoding and decoding. + + diff --git a/org.glite.jobid.api-java/src/org/glite/jobid/api_java/CheckedString.java b/org.glite.jobid.api-java/src/org/glite/jobid/api_java/CheckedString.java index ec8dedd..13ec053 100755 --- a/org.glite.jobid.api-java/src/org/glite/jobid/api_java/CheckedString.java +++ b/org.glite.jobid.api-java/src/org/glite/jobid/api_java/CheckedString.java @@ -22,9 +22,7 @@ public class CheckedString { throw new IllegalArgumentException("checkedString is null"); } - checkedString = checkedString.replaceAll("[\\\"]", "\\\\\""); - checkedString = checkedString.replaceAll("[\n]", "\\\\\\\\n"); - this.checkedString = checkedString; + setCheckedString(checkedString); } /** @@ -44,6 +42,8 @@ public class CheckedString { public void setCheckedString(String checkedString) { checkedString = checkedString.replaceAll("[\\\"]", "\\\\\""); checkedString = checkedString.replaceAll("[\n]", "\\\\\\\\n"); + checkedString = checkedString.replaceAll("[/]", "_"); + checkedString = checkedString.replaceAll("[\\+]", "-"); this.checkedString = checkedString; } @@ -52,6 +52,7 @@ public class CheckedString { * * @return converted string */ + @Override public String toString() { return checkedString; } diff --git a/org.glite.jobid.api-java/src/org/glite/jobid/api_java/Jobid.java b/org.glite.jobid.api-java/src/org/glite/jobid/api_java/Jobid.java index 9cdedea..e65f527 100755 --- a/org.glite.jobid.api-java/src/org/glite/jobid/api_java/Jobid.java +++ b/org.glite.jobid.api-java/src/org/glite/jobid/api_java/Jobid.java @@ -1,6 +1,5 @@ package org.glite.jobid.api_java; -import java.math.BigInteger; import java.net.UnknownHostException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; @@ -29,7 +28,8 @@ public class Jobid { /** * Creates new instace of JobId with BK server address and port number, unique part - * is generated + * is generated. If some exception is catched during generating the unique part, then + * System.exit(-1); is called. * * @param bkserver BK server address * @param port BK server port @@ -69,41 +69,14 @@ public class Jobid { new Random().nextInt(999999); digest.update(unique.getBytes(),0,unique.length()); - unique = new BigInteger(1,digest.digest()).toString(16); + Base64 base64 = new Base64(); + byte[] tmp = base64.encode(digest.digest()); + unique = new CheckedString(new String(tmp, 0, tmp.length-2)).toString(); } catch (NoSuchAlgorithmException ex) { System.err.println(ex); + System.exit(-1); } - - Base64 base64 = new Base64(); - byte[] tmp = base64.decode(unique.getBytes()); - boolean test = false; - while(!test) { - test = true; - for (int i = 0; i < tmp.length; i++) { - if (tmp[i] < 0) { - tmp[i] = (byte)(-1*tmp[i]); - test = false; - } - if (tmp[i] <= 47) { - tmp[i] = (byte)(10+tmp[i]); - test = false; - } - if (tmp[i] <= 64 && tmp[i] >= 58) { - tmp[i] = (byte)(7+tmp[i]); - test = false; - } - if (tmp[i] <= 96 && tmp[i] >= 91) { - tmp[i] = (byte)(6+tmp[i]); - test = false; - } - if (tmp[i] >= 123) { - tmp[i] = (byte)(5-tmp[i]); - test = false; - } - } - } - unique = new String(tmp); } /**