|
|
Posted on 1/2/2015 8:54:24 PM
|
|
|
|

This post was last edited by Delver_Si on 2015-1-2 22:21
ps: They all call apache Commons packages [mw_shl_code=java,true]package security; import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.digest.DigestUtils;
/** * @author Delver_Si
* */ public class EncodeAndDecode { /** * MD5 encryption * @param str * @return */ public static String Md5encode(String str) { return DigestUtils.md5Hex(str); }
/** * Base64 encryption * @param str * @return */ public static String Base64encode(String str) { byte[] b = Base64.encodeBase64(str.getBytes(), true); return new String(b); } /** * Base64 decryption * @param str * @return */ public static String Base64decode(String str) { byte[] b = Base64.decodeBase64(str.getBytes()); return new String(b); }
/** * Generate SHA1 */ public static String SHA1encode(String str) { return DigestUtils.sha1Hex(str); }
} [/mw_shl_code]
[mw_shl_code=java,true]package security;
import java.io.ByteArrayOutputStream;
import org.apache.commons.exec.CommandLine; import org.apache.commons.exec.DefaultExecutor; import org.apache.commons.exec.PumpStreamHandler;
public class Exec { /** * Execute system commands * @param command * @return */ public static String exec(String command) {
try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ByteArrayOutputStream errorStream = new ByteArrayOutputStream();
CommandLine commandline = CommandLine.parse(command);
DefaultExecutor exec = new DefaultExecutor();
exec.setExitValues(null);
PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream,errorStream);
exec.setStreamHandler(streamHandler);
exec.execute(commandline);
String out = outputStream.toString("gbk");
String error = errorStream.toString("gbk");
return out+error;
} catch (Exception e) { e.printStackTrace(); return e.toString();
}
}
} [/mw_shl_code]
[mw_shl_code=java,true]package test; import security. EncodeAndDecode; import security. Exec;
public class Test { public static void main(String[] args) { System.out.println(EncodeAndDecode.Md5encode("whsvse.com")); System.out.println(EncodeAndDecode.Base64encode("whsvse.com")); System.out.println(EncodeAndDecode.Base64decode("d2hzdnNlLmNvbQ=="));
String str = Exec.exec("ping baidu.com"); System.out.println(str); }
} [/mw_shl_code]
Annex :commons-codec-1.10.jar (Toolkits used in Commons projects to handle common encoding methods such as DES, SHA1, MD5, Base64, URL, Soundx, etc.) commons-exec-1.3.jar( Apache Commons Exec is a Java project on Apache that provides some common methods for running external processes)
|
Previous:handwritten jsp backdoorNext:Tor Browser – A browser that allows you to surf the web anonymously
|