This article is a mirror article of machine translation, please click here to jump to the original article.

View: 15278|Reply: 2

[JavaSE] Java MD5 encryption, Base64 encryption and decryption Java executes system command source code

[Copy link]
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





1.png (181.13 KB, Number of downloads: 379)

coder exec.rar

267.93 KB, Download times: 0, Download points: -1 prestige, -1 contribution

Selling Price:2 MB [Recording]  [purchase]





Previous:handwritten jsp backdoor
Next:Tor Browser – A browser that allows you to surf the web anonymously
Posted on 1/2/2015 9:06:45 PM |
I don't understand what the picture means I don't like Apache, although Apache's components are more powerful
 Landlord| Posted on 1/2/2015 9:10:15 PM |
admin posted on 2015-1-2 21:06
I don't understand what the picture means I don't like Apache, although Apache's components are more powerful

md5 encryption whsvse.com base64 encryption and decryption, and execute the ping command
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com