⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ecdsasigtest.java

📁 关于J2me自动登录的源代码实例工具属于简体中文版
💻 JAVA
字号:
package MIDlets;import java.io.*;import java.util.*;import javax.microedition.midlet.*;import javax.microedition.lcdui.*;import javax.microedition.io.*;import javax.microedition.rms.*;//import XMLDsig.*;import org.kxml.*;import org.kxml.parser.*;import org.kxml.kdom.*;public class ECDSASigTest extends MIDlet implements CommandListener {     private Display display;  // Three on-screen command buttons.  private Command cancelCommand;  private Command doneCommand;  private Command fetchCommand;  // TextField allows the user to input URL.  private TextField textField;  // The fetch truncates after 2048 bytes to avoid using  // too much memory.   private int length = 2048;  public ECDSASigTest() throws Exception {    // Initialize display and command objects.    display = Display.getDisplay(this);    cancelCommand = new Command("CANCEL", Command.CANCEL, 1);    doneCommand = new Command("DONE", Command.CANCEL, 1);    fetchCommand = new Command("FETCH", Command.SCREEN, 1);  }  /**   * Ask for URL in the initial screen.   **/  public void startApp() {    // Form with TextField to ask for URL.    Form form = new Form("ECDSA Sig Test");    textField = new TextField("URL:", "",                              80, TextField.ANY);    form.append( textField );    // Two buttons on the form.    form.addCommand(cancelCommand);    form.addCommand(fetchCommand);    // The CommandListener is this MIDlet itself.    form.setCommandListener( (CommandListener) this);    // Display the form on the LCD screen.    display.setCurrent(form);  }  public void pauseApp() {  }  public void destroyApp(boolean unconditional) {  }  /**   * Handle events generated by the Commands in the GUI.   **/  public void commandAction(Command command, Displayable screen) {    if (command == cancelCommand) {      // Quit this MIDlet if "CANCEL" button is pressed.      destroyApp(false);      notifyDestroyed();    } else if (command == doneCommand) {      // "DONE" is the same as "CANCEL"      destroyApp(false);      notifyDestroyed();    } else if (command == fetchCommand) {      try {        // Get the target URL from the TextField.        String url = "http://" + textField.getString();        url = url.trim();        HttpConnection conn = (HttpConnection) Connector.open( url );        conn.setRequestMethod(HttpConnection.GET);        // Get the response stream from the server.        DataInputStream is = conn.openDataInputStream();          InputStreamReader reader = new InputStreamReader(is);        XmlParser parser = new XmlParser (reader);        Document doc = new Document();        doc.parse(parser);        Element signedMesg = doc.getRootElement();        String mesg = signedMesg.getElement("mesg").getText();        String digest = signedMesg.getElement("Signature").getElement("SignedInfo").getElement("DigestValue").getText();        String key_q = signedMesg.getElement("Signature").getElement("KeyInfo").getElement("KeyValue").getElement("ECKeyValue").getElement("Q").getText();        String key_a = signedMesg.getElement("Signature").getElement("KeyInfo").getElement("KeyValue").getElement("ECKeyValue").getElement("A").getText();        String key_b = signedMesg.getElement("Signature").getElement("KeyInfo").getElement("KeyValue").getElement("ECKeyValue").getElement("B").getText();        String key_n = signedMesg.getElement("Signature").getElement("KeyInfo").getElement("KeyValue").getElement("ECKeyValue").getElement("N").getText();        String key_G = signedMesg.getElement("Signature").getElement("KeyInfo").getElement("KeyValue").getElement("ECKeyValue").getElement("G").getText();        String key_Q = signedMesg.getElement("Signature").getElement("KeyInfo").getElement("KeyValue").getElement("ECKeyValue").getElement("QQ").getText();        String sig_r = signedMesg.getElement("Signature").getElement("SignatureValue").getElement("R").getText();        String sig_s = signedMesg.getElement("Signature").getElement("SignatureValue").getElement("S").getText();        // Close response stream.        is.close();//        if ( digest.equals(ECDSASigUtil.getDigest(mesg)) ) {//          mesg = mesg + "\nDigest is verified";//          if ( ECDSASigUtil.verify(digest, sig_r, sig_s,//                                 key_q, key_a, key_b, key_n,//                                 key_G, key_Q) ) {//            mesg = mesg + "\nSignature is verified";//          } else {//            mesg = mesg + "\nSignature is failed";//          }//        } else {//          mesg = mesg + "\nDigest is failed";//        }        TextBox textBox = new TextBox("Message", null,                                      length, TextField.ANY);        textBox.setString( mesg );        textBox.addCommand(doneCommand);        textBox.setCommandListener( (CommandListener) this);        display.setCurrent(textBox);        conn.close();      } catch (Exception e) {        System.out.print(e.getMessage());        e.printStackTrace();      }    }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -