small change

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@945 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
borg-0300 20 years ago
parent d77b982083
commit ee7d847869

@ -3,7 +3,10 @@
// (C) by Michael Peter Christen; mc@anomic.de
// first published on http://www.anomic.de
// Frankfurt, Germany, 2004
// last major change: 13.05.2004
//
// $LastChangedDate$
// $LastChangedRevision$
// $LastChangedBy$
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@ -43,7 +46,6 @@ package de.anomic.tools;
import java.text.SimpleDateFormat;
import java.util.Locale;
import java.util.Random;
import de.anomic.server.serverCodings;
public class crypt {
@ -57,7 +59,7 @@ public class crypt {
public static String randomSalt() {
// generate robust 48-bit random number
long salt =
final long salt =
(saltrandom.nextLong() & 0XffffffffffffL) +
(System.currentTimeMillis() & 0XffffffffffffL) +
((1001 * saltcounter) & 0XffffffffffffL);
@ -108,22 +110,24 @@ public class crypt {
}
public static String simpleEncode(String content, String key, char method) {
if (key == null) key = "NULL";
if (method == 'p') return "p|" + content;
if (method == 'b') return "b|" + serverCodings.enhancedCoder.encodeBase64String(content);
if (method == 'z') return "z|" + serverCodings.enhancedCoder.encodeBase64(gzip.gzipString(content));
return null;
if (key == null) { key = "NULL"; }
switch (method) {
case 'p' : return "p|" + content;
case 'b' : return "b|" + serverCodings.enhancedCoder.encodeBase64String(content);
case 'z' : return "z|" + serverCodings.enhancedCoder.encodeBase64(gzip.gzipString(content));
default : return null;
}
}
public static String simpleDecode(String encoded, String key) {
if ((encoded == null) || (encoded.length() < 3)) return null;
if (encoded.charAt(1) != '|') return encoded; // not encoded
char method = encoded.charAt(0);
encoded = encoded.substring(2);
if (method == 'p') return encoded;
if (method == 'b') return serverCodings.enhancedCoder.decodeBase64String(encoded);
if (method == 'z') return gzip.gunzipString(serverCodings.enhancedCoder.decodeBase64(encoded));
return null;
if (encoded == null || encoded.length() < 3) { return null; }
if (encoded.charAt(1) != '|') { return encoded; } // not encoded
switch (encoded.charAt(0)) {
case 'b' : return serverCodings.enhancedCoder.decodeBase64String(encoded.substring(2));
case 'z' : return gzip.gunzipString(serverCodings.enhancedCoder.decodeBase64(encoded.substring(2)));
case 'p' : return encoded.substring(2);
default : return null;
}
}
}
Loading…
Cancel
Save