JFrame implements batch acquisition of the Android installation package security certificate MD5, jframeandroid

Source: Internet
Author: User

JFrame implements batch acquisition of the Android installation package security certificate MD5, jframeandroid

Today, I met a requirement to obtain the MD5 of all apk signatures. Below is a tool I implemented using Java SE to paste the core source code and hope to help anyone who needs it.

The interface is as follows:


Only define the directory where the .apk file is located. The core code is as follows:

Public class ReadCmdLine {private static MD5Window window; private static String inputPath; public static void main (String args []) {window = new MD5Window (); window. setVisible (true); initWindow ();} private static void initWindow () {// file directory text box window. getFilePathButton (). addActionListener (new ActionListener () {@ Overridepublic void actionreceivmed (ActionEvent arg0) {JFileChooser jfc = new JFileChooser (); jfc. SetFileSelectionMode (JFileChooser. FILES_AND_DIRECTORIES); jfc. showDialog (new JLabel (), "select"); File file = jfc. getSelectedFile (); notDirectoryExcute (file) ;}}); // run the window button. getBeginButton (). addActionListener (new ActionListener () {@ Overridepublic void actionreceivmed (ActionEvent arg0) {inputPath = window. getJTextFiled (); if (inputPath! = Null &&! "". Equals (inputPath. trim () {notDirectoryExcute (new File (inputPath) ;}}); // clear the result button window. getClearButton (). addActionListener (new ActionListener () {@ Overridepublic void actionreceivmed (ActionEvent arg0) {window. setTextArea ("") ;}}) ;}/ *** determines whether it is a directory. If not, run ** @ param file */public static void notDirectoryExcute (File file) {if (file. isDirectory () {inputPath = file. getAbsolutePath (); window. setJTextFile D (inputPath); File [] fiels = file. listFiles (); for (int I = 0; I <fiels. length; I ++) {String absPath = fiels [I]. getAbsolutePath (); if (absPath. contains (". apk ") {excute (absPath) ;}} else {JOptionPane. showMessageDialog (window, "Select Directory") ;}/ *** core logic *** @ param absPath */public static void excute (String absPath) {// 1、read CERT from .apk. RSA file String appName = absPath. substring (absPath. lastIndexOf ("_") + 1, abs Path. lastIndexOf ("."); try {if (absPath! = Null) {readZipFile (absPath) ;}} catch (Exception e) {e. printStackTrace ();} // 2. Execute the keytool command to obtain MD5Process process = null; List <String> processList = new ArrayList <String> (); try {process = runtime.getruntime(cmd.exe c ("keytool-printcert-file D:/test/CERT. RSA "); BufferedReader input = new BufferedReader (new InputStreamReader (process. getInputStream (); String line = ""; while (line = input. readLine ())! = Null) {processList. add (line);} input. close ();} catch (IOException e) {e. printStackTrace ();} // filter content for (String line: processList) {if (line. contains ("MD5") {window. setTextArea (window. getTextArea () + String. format ("%-30 s", appName) + line. trim () + "\ n ");}}} /*** read compressed file content ** @ param file path of the compressed file * @ throws Exception */public static void readZipFile (String file) throws Exception {ZipFile zf = new ZipFile (file); InputStream in = new BufferedInputStream (new FileInputStream (file); ZipInputStream zin = new ZipInputStream (in ); file outFile = new File ("D: \ test \ CERT. RSA "); OutputStream out = new FileOutputStream (outFile); InputStream rsaStream = zf. getInputStream (zf. getEntry ("META-INF/CERT. RSA "); byte [] buf1 = new byte [1024]; int len; while (len = rsaStream. read (buf1)> 0) {out. write (buf1, 0, len);} rsaStream. close (); out. close (); in. close (); zin. closeEntry ();}}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.