├── .gitattributes ├── .gitignore ├── README.md ├── doc ├── crack.gif ├── load.png ├── server.png ├── tab.png └── test.gif ├── jsEncrypter.iml ├── pom.xml ├── script ├── nodejs_server.js └── phantomjs_server.js ├── src └── main │ └── java │ └── burp │ ├── BurpExtender.java │ ├── GUI.java │ ├── HttpClient.java │ ├── Menu.java │ └── Utils.java └── test ├── TestScript ├── Base64 │ ├── base64.js │ └── jsEncrypter_base64.js ├── RSA │ ├── jsEncrypter_rsa.js │ └── jsencrypt.js ├── des │ ├── des.js │ └── jsEncrypter_des.js ├── md5 │ ├── jsEncrypter_md5.js │ └── md5.js ├── sha1 │ ├── jsEncrypter_sha1.js │ └── sha1.js ├── sha256 │ ├── crypto-js.js │ └── jsEncrypter_sha256.js ├── sha384 │ ├── crypto-js.js │ └── jsEncrypter_sha384.js └── sha512 │ ├── crypto-js.js │ └── jsEncrypter_sha512.js └── webapp ├── index.html ├── js ├── base64.js ├── crypto-js.js ├── jquery-3.2.1.min.js ├── jsencrypt.js ├── md5.js └── sha1.js ├── key ├── rsa_private_key.pem └── rsa_public_key.pem ├── login_check.php └── rsa.php /.gitattributes: -------------------------------------------------------------------------------- 1 | *.js linguist-language=Java 2 | *.css linguist-language=Java 3 | *.html linguist-language=Java 4 | *.php linguist-language=Java -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | /.idea/ 3 | /out/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

jsEncrypter | 前端加密Fuzz插件

2 | 3 |

4 | 5 | 6 | 7 |

8 | 9 | 10 | ## 0x01 插件简介 11 | 12 | 本插件使用`phantomjs`启动前端加密函数对数据进行加密,方便对加密数据输入点进行fuzz,比如可以使用于前端加密传输爆破等场景。 13 | 14 | ![界面](./doc/tab.png) 15 | 16 | ## 0x02 插件编译 17 | 18 | 安装好maven,然后执行以下命令即可编译成功: 19 | 20 | ``` 21 | mvn package 22 | ``` 23 | 24 | ## 0x03 插件使用 25 | #### 3.1 运行靶机 26 | 项目提供了一个用php编写的靶机(jsEncrypter/server),靶机提供了7个算法对密码进行加密后传输,后台解密,最后进行密码匹配。 27 | 28 | * base64 29 | * md5 30 | * sha1 31 | * sha254 32 | * sha384 33 | * sha512 34 | * RSA 35 | 36 | ![靶机](./doc/server.png) 37 | 38 | #### 3.2 编写phantomJS运行脚本 39 | 40 | `jsEncrypter/js/jsEncrypter_base.js`为插件phantomJS脚本模板。我们只需要将实现加密算法的js文件引入模板脚本,并在模板脚本的js_encrypt函数体中完成对加密函数的调用。 41 | 42 | ```` 43 | ... 44 | /* 1.在这引入实现加密所有js文件,注意引入顺序和网页一致 */ 45 | loadScript("script-1.js"); 46 | loadScript("script-2.js"); 47 | loadScript("script-n.js"); 48 | /**********************************************/ 49 | 50 | ... 51 | 52 | function jsEncrypt(burp_payload){ 53 | var new_payload; 54 | /* 2.在这里编写调用加密函数进行加密的代码,并把结果赋值给new_payload */ 55 | 56 | /*********************************************************/ 57 | return new_payload; 58 | } 59 | ... 60 | ```` 61 | 62 | 项目jsEncrypter/server/TestScript目录下是编写好的对应靶机各个加密算法的phantomJS脚本,可以参考! 63 | 64 | #### 3.3 运行phantomJS并测试 65 | 运行phantomJS 66 | 67 | ``` 68 | >phantomJS.exe jsEncrypter_sha1.js 69 | ``` 70 | 71 | 测试的目的是为了确保我们编写的phantomJS脚本能够正常加密payload。 72 | 73 | ![运行phantomJS并测试](./doc/test.gif) 74 | 75 | #### 3.4 抓包暴力破解 76 | ![抓包暴力破解](./doc/crack.gif) 77 | 78 | ## 0x04 相关文章 79 | * [编写加密传输爆破插件jsEncrypter](http://gv7.me/articles/2017/jsEncrypter/) 80 | * [快速定位前端加密方法](http://gv7.me/articles/2018/fast-locate-the-front-end-encryption-method/) 81 | * [解决jsEncrypter脚本错误代码不报错问题](http://gv7.me/articles/2018/solve-jsEncrypter-script-error-code-is-not-wrong/) 82 | * [jsEncrypter的Node.js版server脚本](http://gv7.me/articles/2018/jsEncrypter-nodejs-server-script/) -------------------------------------------------------------------------------- /doc/crack.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/c0ny1/jsEncrypter/b35fe5b68c65f8375a288e1e6cf7dd6d69630381/doc/crack.gif -------------------------------------------------------------------------------- /doc/load.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/c0ny1/jsEncrypter/b35fe5b68c65f8375a288e1e6cf7dd6d69630381/doc/load.png -------------------------------------------------------------------------------- /doc/server.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/c0ny1/jsEncrypter/b35fe5b68c65f8375a288e1e6cf7dd6d69630381/doc/server.png -------------------------------------------------------------------------------- /doc/tab.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/c0ny1/jsEncrypter/b35fe5b68c65f8375a288e1e6cf7dd6d69630381/doc/tab.png -------------------------------------------------------------------------------- /doc/test.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/c0ny1/jsEncrypter/b35fe5b68c65f8375a288e1e6cf7dd6d69630381/doc/test.gif -------------------------------------------------------------------------------- /jsEncrypter.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | me.gv7.tools.burpextend 8 | jsEncrypter 9 | 0.3.2 10 | 11 | 12 | 13 | 14 | net.portswigger.burp.extender 15 | burp-extender-api 16 | 1.7.22 17 | 18 | 19 | 20 | 21 | 22 | 23 | org.apache.maven.plugins 24 | maven-assembly-plugin 25 | 26 | 27 | package 28 | 29 | single 30 | 31 | 32 | 33 | 34 | 35 | jar-with-dependencies 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /script/nodejs_server.js: -------------------------------------------------------------------------------- 1 | /** 2 | * author: c0ny1 3 | * date: 2018-4-14 4 | * file: nodejs_server.js 5 | */ 6 | var http = require('http'); 7 | var querystring = require('querystring'); 8 | var host = '127.0.0.1'; //地址 9 | var port = '1664'; //端口 10 | //require('your_encrypte_script.js'); /*引入实现加密的js文件*/ 11 | require('./sha384.js'); 12 | // 处理函数 13 | function js_encrypt(payload){ 14 | var newpayload; 15 | /**********在这里编写调用加密函数进行加密的代码************/ 16 | 17 | /**********************************************************/ 18 | return newpayload; 19 | } 20 | var server = http.createServer(function(request,response){ 21 | if(request.method === 'POST'){ 22 | var postData = ''; 23 | request.on('data',function(params){ 24 | postData += params; 25 | }); 26 | 27 | request.on('end',function(){ 28 | var dataString = postData.toString(); 29 | var dataObj = querystring.parse(dataString); 30 | var payload = dataObj.payload; 31 | var encrypt_payload = js_encrypt(payload); 32 | console.log('[+] ' + payload + ':' + encrypt_payload); 33 | 34 | response.statusCode = 200; 35 | response.write(encrypt_payload); 36 | response.end(); 37 | }); 38 | }else{ 39 | response.statusCode = 200; 40 | response.write("^_^\n\rhello jsEncrypter!"); 41 | response.end(); 42 | } 43 | }); 44 | server.listen(port, host, function () { 45 | console.log("[!] ^_^"); 46 | console.log("[*] nodejs server start!"); 47 | console.log("[+] address: http://"+host+":"+port); 48 | }); -------------------------------------------------------------------------------- /script/phantomjs_server.js: -------------------------------------------------------------------------------- 1 | /** 2 | * author: c0ny1 3 | * date: 2017-12-16 4 | * last update: 2020-03-03 5 | */ 6 | var fs = require('fs'); 7 | var webserver = require('webserver'); 8 | server = webserver.create(); 9 | 10 | var logfile = 'jsEncrypter.log'; 11 | var host = '127.0.0.1'; 12 | var port = '1664'; 13 | 14 | /* 1.在这引入实现加密所有js文件,注意引入顺序和网页一致 */ 15 | loadScript("script-1.js"); 16 | loadScript("script-2.js"); 17 | loadScript("script-n.js"); 18 | /**********************************************/ 19 | 20 | function loadScript(scriptName) { 21 | var isSuccess = phantom.injectJs(scriptName); 22 | if(isSuccess){ 23 | console.log("[*] load " + scriptName + " successful") 24 | }else{ 25 | console.log("[!] load " + scriptName + " fail") 26 | console.log("[*] phantomjs server exit"); 27 | phantom.exit(); 28 | } 29 | } 30 | 31 | function jsEncrypt(burp_payload){ 32 | var new_payload; 33 | /* 2.在这里编写调用加密函数进行加密的代码,并把结果赋值给new_payload */ 34 | 35 | /*********************************************************/ 36 | return new_payload; 37 | } 38 | 39 | console.log("[*] Phantomjs server for jsEncrypter started successfully!"); 40 | console.log("[*] address: http://"+host+":"+port); 41 | console.log("[!] ^_^"); 42 | 43 | var service = server.listen(host+':'+port,function(request, response){ 44 | try{ 45 | if(request.method == 'POST'){ 46 | var payload = request.post['payload']; 47 | var encrypt_payload = jsEncrypt(payload); 48 | var log = payload + ':' + encrypt_payload; 49 | console.log('[+] ' + log); 50 | fs.write(logfile,log + '\n', 'w+'); 51 | response.statusCode = 200; 52 | response.setEncoding('UTF-8'); 53 | response.write(encrypt_payload.toString()); 54 | response.close(); 55 | }else{ 56 | response.statusCode = 200; 57 | response.setEncoding('UTF-8'); 58 | response.write("^_^\n\rhello jsEncrypter!"); 59 | response.close(); 60 | } 61 | }catch(e){ 62 | //console.log('[Error]'+e.message+' happen '+e.line+'line'); 63 | console.log('\n-----------------Error Info--------------------'); 64 | var fullMessage = "Message: "+e.toString() + ':'+ e.line; 65 | for (var p in e) { 66 | fullMessage += "\n" + p.toUpperCase() + ": " + e[p]; 67 | } 68 | console.log(fullMessage); 69 | console.log('---------------------------------------------'); 70 | response.statusCode = 200; 71 | response.setEncoding('UTF-8'); 72 | response.write(fullMessage); 73 | response.close(); 74 | console.log('[*] phantomJS exit!'); 75 | phantom.exit(); 76 | } 77 | }); -------------------------------------------------------------------------------- /src/main/java/burp/BurpExtender.java: -------------------------------------------------------------------------------- 1 | package burp; 2 | 3 | import java.awt.Component; 4 | import java.io.PrintWriter; 5 | import javax.swing.SwingUtilities; 6 | 7 | public class BurpExtender implements IBurpExtender,IIntruderPayloadProcessor,ITab { 8 | public final static String extensionName = "jsEncrypter"; 9 | public final static String version ="0.3.2"; 10 | public static IBurpExtenderCallbacks callbacks; 11 | public static IExtensionHelpers helpers; 12 | public static PrintWriter stdout; 13 | public static PrintWriter stderr; 14 | public static GUI gui; 15 | 16 | @Override 17 | public void registerExtenderCallbacks(IBurpExtenderCallbacks callbacks) { 18 | this.callbacks = callbacks; 19 | this.helpers = callbacks.getHelpers(); 20 | this.stdout = new PrintWriter(callbacks.getStdout(),true); 21 | this.stderr = new PrintWriter(callbacks.getStderr(),true); 22 | 23 | callbacks.setExtensionName(extensionName+" "+version); 24 | callbacks.registerContextMenuFactory(new Menu()); 25 | callbacks.registerIntruderPayloadProcessor(this); 26 | 27 | BurpExtender.this.gui = new GUI(); 28 | SwingUtilities.invokeLater(new Runnable() 29 | { 30 | public void run() 31 | { 32 | BurpExtender.this.callbacks.addSuiteTab(BurpExtender.this); 33 | stdout.println(Utils.getBanner()); 34 | } 35 | }); 36 | 37 | } 38 | 39 | // 40 | // 实现IIntruderPayloadProcessor 41 | // 42 | 43 | @Override 44 | public String getProcessorName() { 45 | return extensionName; 46 | } 47 | 48 | @Override 49 | public byte[] processPayload(byte[] currentPayload, byte[] originalPayload, byte[] baseValue) { 50 | String payload = new String(currentPayload); 51 | String newPayload = Utils.sendPayload(payload); 52 | return helpers.stringToBytes(newPayload); 53 | } 54 | 55 | // 56 | // 实现ITab 57 | // 58 | 59 | @Override 60 | public String getTabCaption() { 61 | return extensionName; 62 | } 63 | 64 | @Override 65 | public Component getUiComponent() { 66 | return gui.getComponet(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/burp/GUI.java: -------------------------------------------------------------------------------- 1 | package burp; 2 | 3 | import java.awt.BorderLayout; 4 | import java.awt.Color; 5 | import javax.swing.*; 6 | import javax.swing.border.EmptyBorder; 7 | import java.awt.FlowLayout; 8 | import java.awt.Component; 9 | import java.awt.event.ActionListener; 10 | import java.awt.event.ActionEvent; 11 | import java.io.UnsupportedEncodingException; 12 | 13 | public class GUI{ 14 | private JPanel contentPane; 15 | private JLabel lbHost; 16 | private JTextField tfHost; 17 | private JLabel lbPort; 18 | private JTextField tfPort; 19 | private JLabel lbTimeout; 20 | private JTextField tfTimeout; 21 | private JButton btnConn; 22 | private JLabel lbConnectInfo; 23 | private JLabel lbConnectStatus; 24 | private JButton btnTest; 25 | private JSplitPane splitPane; 26 | private Component verticalStrut; 27 | private JTextArea taTestPayload; 28 | //private JTextPane taTestPayload; 29 | private JScrollPane spTestPayload; 30 | private JTextArea taResultPayload; 31 | private JScrollPane spResultPayload; 32 | private boolean isSucces = false; 33 | private String testPayload[] = { 34 | "123456","a123456","123456a","5201314", 35 | "111111","woaini1314","qq123456","123123", 36 | "000000","1qaz2wsx","1q2w3e4r","qwe123", 37 | "7758521","123qwe","a123123","123456aa", 38 | "woaini520","woaini","100200","1314520" 39 | }; 40 | 41 | public GUI() { 42 | contentPane = new JPanel(); 43 | contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); 44 | contentPane.setLayout(new BorderLayout(0, 0)); 45 | 46 | JPanel panel = new JPanel(); 47 | FlowLayout flowLayout = (FlowLayout) panel.getLayout(); 48 | flowLayout.setAlignment(FlowLayout.LEFT); 49 | contentPane.add(panel, BorderLayout.NORTH); 50 | 51 | lbHost = new JLabel("Host:"); 52 | panel.add(lbHost); 53 | tfHost = new JTextField(); 54 | tfHost.setColumns(20); 55 | tfHost.setText("127.0.0.1"); 56 | panel.add(tfHost); 57 | 58 | verticalStrut = Box.createVerticalStrut(20); 59 | panel.add(verticalStrut); 60 | lbPort = new JLabel("Port:"); 61 | panel.add(lbPort); 62 | tfPort = new JTextField(); 63 | tfPort.setText("1664"); 64 | panel.add(tfPort); 65 | tfPort.setColumns(10); 66 | 67 | verticalStrut = Box.createVerticalStrut(20); 68 | panel.add(verticalStrut); 69 | lbTimeout = new JLabel("Timeout:"); 70 | panel.add(lbTimeout); 71 | tfTimeout = new JTextField(); 72 | tfTimeout.setText("5000"); 73 | panel.add(tfTimeout); 74 | tfTimeout.setColumns(10); 75 | 76 | btnConn = new JButton("Connect"); 77 | btnConn.setToolTipText("Test the connection phantomJS"); 78 | btnConn.addActionListener(new ActionListener() { 79 | public void actionPerformed(ActionEvent arg0) { 80 | GUI.this.TestConnect(); 81 | } 82 | }); 83 | panel.add(btnConn); 84 | 85 | lbConnectInfo = new JLabel("IsConnect:"); 86 | panel.add(lbConnectInfo); 87 | lbConnectStatus = new JLabel("unknown"); 88 | lbConnectStatus.setForeground(new Color(0, 0, 255)); 89 | panel.add(lbConnectStatus); 90 | 91 | btnTest = new JButton("Test"); 92 | btnTest.addActionListener(new ActionListener() { 93 | public void actionPerformed(ActionEvent arg0) { 94 | GUI.this.TestConnect(); 95 | if(isSucces){ 96 | GUI.this.TestPayload(); 97 | BurpExtender.stdout.println("[+] test..."); 98 | }else{ 99 | JOptionPane.showMessageDialog(contentPane, "Please check if you can connect phantomJS!", "alert", JOptionPane.ERROR_MESSAGE); 100 | } 101 | } 102 | }); 103 | 104 | btnTest.setToolTipText("Start test run"); 105 | panel.add(btnTest); 106 | 107 | splitPane = new JSplitPane(); 108 | splitPane.setDividerLocation(0.5); 109 | contentPane.add(splitPane, BorderLayout.CENTER); 110 | 111 | taTestPayload = new JTextArea(); 112 | taTestPayload.setColumns(30); 113 | String tmp = ""; 114 | for (String payload : testPayload) { 115 | //JTextArea.append 会导致汉化版无法换行 116 | //taTestPayload.append(payload + System.lineSeparator()); 117 | payload += System.lineSeparator(); 118 | tmp += payload; 119 | } 120 | taTestPayload.setText(tmp); 121 | 122 | spTestPayload = new JScrollPane(taTestPayload, 123 | ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, 124 | ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); 125 | splitPane.setLeftComponent(spTestPayload); 126 | 127 | taResultPayload = new JTextArea(); 128 | taResultPayload.setColumns(30); 129 | spResultPayload = new JScrollPane(taResultPayload, 130 | ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, 131 | ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); 132 | splitPane.setRightComponent(spResultPayload); 133 | 134 | BurpExtender.callbacks.customizeUiComponent(panel); 135 | BurpExtender.callbacks.customizeUiComponent(btnTest); 136 | BurpExtender.callbacks.customizeUiComponent(btnConn); 137 | BurpExtender.callbacks.customizeUiComponent(taTestPayload); 138 | BurpExtender.callbacks.customizeUiComponent(splitPane); 139 | BurpExtender.callbacks.customizeUiComponent(contentPane); 140 | } 141 | 142 | public Component getComponet(){ 143 | return contentPane; 144 | } 145 | 146 | public Integer getTimeout(){ 147 | return Integer.valueOf(tfTimeout.getText()); 148 | } 149 | 150 | // 发送连接测试,确定是否能连接加密服务端 151 | private void TestConnect(){ 152 | boolean isConn = Utils.sendTestConnect(); 153 | if(isConn){ 154 | BurpExtender.stdout.println("[+] connect success!"); 155 | lbConnectStatus.setText("True"); 156 | isSucces = true; 157 | lbConnectStatus.setForeground(new Color(0,255,0)); 158 | }else{ 159 | BurpExtender.stdout.println("[-] connect fail!"); 160 | lbConnectStatus.setText("False"); 161 | isSucces = false; 162 | lbConnectStatus.setForeground(new Color(255,0,0)); 163 | } 164 | } 165 | 166 | 167 | // 发送测试payload,确定是否加密成功 168 | private void TestPayload() { 169 | taResultPayload.setText(""); 170 | btnTest.setEnabled(false); 171 | SwingUtilities.invokeLater(new Runnable() { 172 | public void run() { 173 | String[] payloads = taTestPayload.getText().split("\r|\n"); 174 | String tmp = ""; 175 | for (String payload : payloads) { 176 | if(payload.equals(null)||payload.equals("")){ 177 | continue; 178 | } 179 | String newPayload = Utils.sendPayload(payload); 180 | newPayload += System.lineSeparator(); 181 | tmp += newPayload; 182 | } 183 | 184 | // 如果是Windows,先UTF-8编码在显示,解决Windows上乱码问题 185 | if(System.getProperty("os.name").toLowerCase().contains("win")){ 186 | tmp = Utils.transformCharset(tmp,"UTF-8"); 187 | } 188 | 189 | taResultPayload.setText(tmp); 190 | btnTest.setEnabled(true); 191 | } 192 | }); 193 | } 194 | 195 | // 获取phantomJS 196 | public String getURL(){ 197 | String URL; 198 | String host = tfHost.getText().trim(); 199 | String port = tfPort.getText().trim(); 200 | URL = String.format("http://%s:%s",host,port); 201 | return URL; 202 | } 203 | } 204 | -------------------------------------------------------------------------------- /src/main/java/burp/HttpClient.java: -------------------------------------------------------------------------------- 1 | package burp; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStreamReader; 6 | import java.io.PrintWriter; 7 | import java.net.HttpURLConnection; 8 | import java.net.MalformedURLException; 9 | import java.net.URL; 10 | import java.net.URLConnection; 11 | 12 | public class HttpClient { 13 | private String url = ""; 14 | private String data = ""; 15 | private Integer connTimeout = 3000; 16 | private Integer readTimeout = 3000; 17 | private String ua = "jsEncrypter client"; 18 | private Integer statusCode = 0; 19 | private String rspData = null; 20 | 21 | public HttpClient(String url){ 22 | this.url = url; 23 | } 24 | 25 | public String getUrl() { 26 | return url; 27 | } 28 | 29 | public void setUrl(String url) { 30 | this.url = url; 31 | } 32 | 33 | public String getData() { 34 | return data; 35 | } 36 | 37 | public void setData(String data) { 38 | this.data = data; 39 | } 40 | 41 | public Integer getConnTimeout() { 42 | return connTimeout; 43 | } 44 | 45 | public void setConnTimeout(Integer connTimeout) { 46 | this.connTimeout = connTimeout; 47 | } 48 | 49 | public Integer getReadTimeout() { 50 | return readTimeout; 51 | } 52 | 53 | public void setReadTimeout(Integer readTimeout) { 54 | this.readTimeout = readTimeout; 55 | } 56 | 57 | public String getUa() { 58 | return ua; 59 | } 60 | 61 | public void setUa(String ua) { 62 | this.ua = ua; 63 | } 64 | 65 | public Integer getStatusCode() { 66 | return statusCode; 67 | } 68 | 69 | public String getRspData() { 70 | return rspData; 71 | } 72 | 73 | public void sendGet(){ 74 | String rspData = ""; 75 | BufferedReader in = null; 76 | try { 77 | URL realUrl = new URL(url); 78 | URLConnection urlConn = realUrl.openConnection(); 79 | HttpURLConnection httpConn = (HttpURLConnection) urlConn; 80 | httpConn.setRequestProperty("user-agent", this.ua); 81 | httpConn.setConnectTimeout(this.connTimeout); 82 | httpConn.setReadTimeout(this.readTimeout); 83 | httpConn.connect(); 84 | 85 | this.statusCode = httpConn.getResponseCode(); 86 | in = new BufferedReader(new InputStreamReader(httpConn.getInputStream())); 87 | String line; 88 | while ((line = in.readLine()) != null) { 89 | rspData += line; 90 | } 91 | }catch (MalformedURLException e){ 92 | rspData = "jsEncrypter wanning:" + e.getMessage(); 93 | }catch (IOException e){ 94 | rspData = "jsEncrypter wanning:" + e.getMessage(); 95 | } 96 | this.rspData = rspData; 97 | } 98 | 99 | public void sendPost(){ 100 | PrintWriter out = null; 101 | String rspData = ""; 102 | BufferedReader in = null; 103 | try { 104 | URL realUrl = new URL(this.url); 105 | URLConnection urlConn = realUrl.openConnection(); 106 | HttpURLConnection httpConn = (HttpURLConnection) urlConn; 107 | httpConn.setRequestProperty("user-agent", this.ua); 108 | httpConn.setConnectTimeout(this.connTimeout); 109 | httpConn.setReadTimeout(this.readTimeout); 110 | 111 | httpConn.setDoOutput(true); 112 | httpConn.setDoInput(true); 113 | out = new PrintWriter(httpConn.getOutputStream()); 114 | out.print(data); 115 | httpConn.connect(); 116 | out.flush(); 117 | 118 | this.statusCode = httpConn.getResponseCode(); 119 | in = new BufferedReader(new InputStreamReader(httpConn.getInputStream())); 120 | String line; 121 | while ((line = in.readLine()) != null) { 122 | rspData += line; 123 | } 124 | }catch (MalformedURLException e){ 125 | rspData = "jsEncrypter wanning:" + e.getMessage(); 126 | }catch (IOException e){ 127 | rspData = "jsEncrypter wanning:" + e.getMessage(); 128 | } 129 | this.rspData = rspData; 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /src/main/java/burp/Menu.java: -------------------------------------------------------------------------------- 1 | package burp; 2 | 3 | import javax.swing.*; 4 | import java.awt.event.ActionEvent; 5 | import java.awt.event.ActionListener; 6 | import java.io.UnsupportedEncodingException; 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | public class Menu implements IContextMenuFactory{ 11 | private int[] selectRange; 12 | 13 | public List createMenuItems(final IContextMenuInvocation invocation) { 14 | List menus = new ArrayList(); 15 | 16 | selectRange = invocation.getSelectionBounds(); 17 | if(invocation.getInvocationContext() != IContextMenuInvocation.CONTEXT_MESSAGE_EDITOR_REQUEST || selectRange[0] == selectRange[1]){ 18 | return menus; 19 | } 20 | 21 | JMenuItem encryptMenu = new JMenuItem("jsEncrypter encrypt"); 22 | 23 | encryptMenu.addActionListener(new ActionListener() { 24 | public void actionPerformed(ActionEvent e) { 25 | IHttpRequestResponse reqRsp = invocation.getSelectedMessages()[0]; 26 | byte[] byteReq = reqRsp.getRequest(); 27 | try { 28 | String strReq = new String(byteReq); 29 | String strSelect = new String(byteReq, selectRange[0],(selectRange[1]-selectRange[0]), "UTF-8"); 30 | String strEncrypt = Utils.sendPayload(strSelect); 31 | StringBuffer sbReq = new StringBuffer(strReq); 32 | sbReq.replace(selectRange[0],selectRange[1],strEncrypt); 33 | byte[] newRequst = BurpExtender.helpers.stringToBytes(sbReq.toString()); 34 | reqRsp.setRequest(newRequst); 35 | } catch (UnsupportedEncodingException er) { 36 | BurpExtender.stderr.println(er.getMessage()); 37 | } 38 | } 39 | }); 40 | 41 | menus.add(encryptMenu); 42 | return menus; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/burp/Utils.java: -------------------------------------------------------------------------------- 1 | package burp; 2 | 3 | import com.sun.org.apache.bcel.internal.generic.NEW; 4 | 5 | public class Utils { 6 | public static String sendPayload(String payload){ 7 | String encryptPayload = ""; 8 | HttpClient hc = new HttpClient(BurpExtender.gui.getURL()); 9 | hc.setConnTimeout(BurpExtender.gui.getTimeout()); 10 | hc.setReadTimeout(BurpExtender.gui.getTimeout()); 11 | String data = "payload=" + payload; 12 | hc.setData(data); 13 | hc.sendPost(); 14 | encryptPayload = hc.getRspData(); 15 | return encryptPayload; 16 | } 17 | 18 | public static boolean sendTestConnect(){ 19 | HttpClient hc = new HttpClient(BurpExtender.gui.getURL()); 20 | hc.setReadTimeout(Integer.valueOf(BurpExtender.gui.getTimeout())); 21 | hc.setConnTimeout(Integer.valueOf(BurpExtender.gui.getTimeout())); 22 | hc.sendGet(); 23 | int n = BurpExtender.helpers.indexOf(hc.getRspData().getBytes(), "hello".getBytes(), false, 0, hc.getRspData().length()); 24 | if((hc.getStatusCode() == 200)&&(n != -1)){ 25 | return true; 26 | }else{ 27 | return false; 28 | } 29 | } 30 | 31 | public static String getBanner(){ 32 | String bannerInfo = 33 | "[+] " + BurpExtender.extensionName + " is loaded\n" 34 | + "[+] ^_^\n" 35 | + "[+]\n" 36 | + "[+] #####################################\n" 37 | + "[+] " + BurpExtender.extensionName + " v" + BurpExtender.version +"\n" 38 | + "[+] anthor: c0ny1\n" 39 | + "[+] email: root@gv7.me\n" 40 | + "[+] github: http://github.com/c0ny1/jsEncrypter\n" 41 | + "[+] ####################################"; 42 | return bannerInfo; 43 | } 44 | 45 | /** 46 | * 转换字符串编码 47 | */ 48 | public static String transformCharset(String str,String charsetName){ 49 | String newStr = null; 50 | try { 51 | newStr = new String(str.getBytes(), charsetName); 52 | }catch (Exception e){ 53 | BurpExtender.stdout.println("[-] Utils.transformCharset erro: " + e.getMessage()); 54 | newStr = str; 55 | } 56 | return newStr; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /test/TestScript/Base64/base64.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Base64 encode / decode 4 | * 5 | * @author haitao.tu 6 | * @date 2010-04-26 7 | * @email tuhaitao@foxmail.com 8 | * 9 | */ 10 | 11 | function Base64() { 12 | 13 | // private property 14 | _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; 15 | 16 | // public method for encoding 17 | this.encode = function (input) { 18 | var output = ""; 19 | var chr1, chr2, chr3, enc1, enc2, enc3, enc4; 20 | var i = 0; 21 | input = _utf8_encode(input); 22 | while (i < input.length) { 23 | chr1 = input.charCodeAt(i++); 24 | chr2 = input.charCodeAt(i++); 25 | chr3 = input.charCodeAt(i++); 26 | enc1 = chr1 >> 2; 27 | enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); 28 | enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); 29 | enc4 = chr3 & 63; 30 | if (isNaN(chr2)) { 31 | enc3 = enc4 = 64; 32 | } else if (isNaN(chr3)) { 33 | enc4 = 64; 34 | } 35 | output = output + 36 | _keyStr.charAt(enc1) + _keyStr.charAt(enc2) + 37 | _keyStr.charAt(enc3) + _keyStr.charAt(enc4); 38 | } 39 | return output; 40 | } 41 | 42 | // public method for decoding 43 | this.decode = function (input) { 44 | var output = ""; 45 | var chr1, chr2, chr3; 46 | var enc1, enc2, enc3, enc4; 47 | var i = 0; 48 | input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); 49 | while (i < input.length) { 50 | enc1 = _keyStr.indexOf(input.charAt(i++)); 51 | enc2 = _keyStr.indexOf(input.charAt(i++)); 52 | enc3 = _keyStr.indexOf(input.charAt(i++)); 53 | enc4 = _keyStr.indexOf(input.charAt(i++)); 54 | chr1 = (enc1 << 2) | (enc2 >> 4); 55 | chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); 56 | chr3 = ((enc3 & 3) << 6) | enc4; 57 | output = output + String.fromCharCode(chr1); 58 | if (enc3 != 64) { 59 | output = output + String.fromCharCode(chr2); 60 | } 61 | if (enc4 != 64) { 62 | output = output + String.fromCharCode(chr3); 63 | } 64 | } 65 | output = _utf8_decode(output); 66 | return output; 67 | } 68 | 69 | // private method for UTF-8 encoding 70 | _utf8_encode = function (string) { 71 | string = string.replace(/\r\n/g,"\n"); 72 | var utftext = ""; 73 | for (var n = 0; n < string.length; n++) { 74 | var c = string.charCodeAt(n); 75 | if (c < 128) { 76 | utftext += String.fromCharCode(c); 77 | } else if((c > 127) && (c < 2048)) { 78 | utftext += String.fromCharCode((c >> 6) | 192); 79 | utftext += String.fromCharCode((c & 63) | 128); 80 | } else { 81 | utftext += String.fromCharCode((c >> 12) | 224); 82 | utftext += String.fromCharCode(((c >> 6) & 63) | 128); 83 | utftext += String.fromCharCode((c & 63) | 128); 84 | } 85 | 86 | } 87 | return utftext; 88 | } 89 | 90 | // private method for UTF-8 decoding 91 | _utf8_decode = function (utftext) { 92 | var string = ""; 93 | var i = 0; 94 | var c = c1 = c2 = 0; 95 | while ( i < utftext.length ) { 96 | c = utftext.charCodeAt(i); 97 | if (c < 128) { 98 | string += String.fromCharCode(c); 99 | i++; 100 | } else if((c > 191) && (c < 224)) { 101 | c2 = utftext.charCodeAt(i+1); 102 | string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); 103 | i += 2; 104 | } else { 105 | c2 = utftext.charCodeAt(i+1); 106 | c3 = utftext.charCodeAt(i+2); 107 | string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); 108 | i += 3; 109 | } 110 | } 111 | return string; 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /test/TestScript/Base64/jsEncrypter_base64.js: -------------------------------------------------------------------------------- 1 | var webserver = require('webserver'); 2 | server = webserver.create(); 3 | 4 | var host = '127.0.0.1'; 5 | var port = '1664'; 6 | 7 | // 加载实现加密算法的js脚本 8 | var wasSuccessful = phantom.injectJs('base64.js');/*引入实现加密的js文件*/ 9 | 10 | // 处理函数 11 | function js_encrypt(payload){ 12 | var newpayload; 13 | /**********在这里编写调用加密函数进行加密的代码************/ 14 | var b = new Base64(); 15 | newpayload = b.encode(payload); 16 | /**********************************************************/ 17 | return newpayload; 18 | } 19 | 20 | if(wasSuccessful){ 21 | console.log("[*] load js successful"); 22 | console.log("[!] ^_^"); 23 | console.log("[*] jsEncrypterJS start!"); 24 | console.log("[+] address: http://"+host+":"+port); 25 | }else{ 26 | console.log('[*] load js fail!'); 27 | } 28 | 29 | var service = server.listen(host+':'+port,function(request, response){ 30 | try{ 31 | if(request.method == 'POST'){ 32 | var payload = request.post['payload']; 33 | var encrypt_payload = js_encrypt(payload); 34 | console.log('[+] ' + payload + ':' + encrypt_payload); 35 | response.statusCode = 200; 36 | response.write(encrypt_payload.toString()); 37 | response.close(); 38 | }else{ 39 | response.statusCode = 200; 40 | response.write("^_^\n\rhello jsEncrypter!"); 41 | response.close(); 42 | } 43 | }catch(e){ 44 | console.log('\n-----------------Error Info--------------------') 45 | var fullMessage = "Message: "+e.toString() + ':'+ e.line; 46 | for (var p in e) { 47 | fullMessage += "\n" + p.toUpperCase() + ": " + e[p]; 48 | } 49 | console.log(fullMessage); 50 | console.log('---------------------------------------------') 51 | console.log('[*] phantomJS exit!') 52 | phantom.exit(); 53 | } 54 | }); -------------------------------------------------------------------------------- /test/TestScript/RSA/jsEncrypter_rsa.js: -------------------------------------------------------------------------------- 1 | var webserver = require('webserver'); 2 | server = webserver.create(); 3 | 4 | var host = '127.0.0.1'; 5 | var port = '1664'; 6 | 7 | // 加载实现加密算法的js脚本 8 | var wasSuccessful = phantom.injectJs('jsencrypt.js');/*引入实现加密的js文件*/ 9 | 10 | // 处理函数 11 | function js_encrypt(payload){ 12 | var newpayload; 13 | /**********在这里编写调用加密函数进行加密的代码************/ 14 | var encrypt = new JSEncrypt(); 15 | var key = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC0Llg1bVZhnyslfezwfeOkvnXWq59bDtmQyHvxkP/38Fw8QQXBfROCgzGc+Te6pOPl6Ye+vQ1rAnisBaP3rMk40i3OpallzVkuwRKydek3V9ufPpZEEH4eBgInMSDiMsggTWxcI/Lvag6eHjkSc67RTrj96oxj0ipVRqjxW4X6HQIDAQAB"; 16 | encrypt.setPublicKey(key); 17 | newpayload = encrypt.encrypt(payload); 18 | /**********************************************************/ 19 | return newpayload; 20 | } 21 | 22 | if(wasSuccessful){ 23 | console.log("[*] load js successful"); 24 | console.log("[!] ^_^"); 25 | console.log("[*] jsEncrypterJS start!"); 26 | console.log("[+] address: http://"+host+":"+port); 27 | }else{ 28 | console.log('[*] load js fail!'); 29 | } 30 | 31 | var service = server.listen(host+':'+port,function(request, response){ 32 | try{ 33 | if(request.method == 'POST'){ 34 | var payload = request.post['payload']; 35 | var encrypt_payload = js_encrypt(payload); 36 | console.log('[+] ' + payload + ':' + encrypt_payload); 37 | response.statusCode = 200; 38 | response.write(encrypt_payload.toString()); 39 | response.close(); 40 | }else{ 41 | response.statusCode = 200; 42 | response.write("^_^\n\rhello jsEncrypter!"); 43 | response.close(); 44 | } 45 | }catch(e){ 46 | console.log('\n-----------------Error Info--------------------') 47 | var fullMessage = "Message: "+e.toString() + ':'+ e.line; 48 | for (var p in e) { 49 | fullMessage += "\n" + p.toUpperCase() + ": " + e[p]; 50 | } 51 | console.log(fullMessage); 52 | console.log('---------------------------------------------') 53 | console.log('[*] phantomJS exit!') 54 | phantom.exit(); 55 | } 56 | }); -------------------------------------------------------------------------------- /test/TestScript/RSA/jsencrypt.js: -------------------------------------------------------------------------------- 1 | var JSEncryptExports = {}; 2 | (function(exports) { 3 | function BigInteger(a,b,c){null!=a&&("number"==typeof a?this.fromNumber(a,b,c):null==b&&"string"!=typeof a?this.fromString(a,256):this.fromString(a,b))}function nbi(){return new BigInteger(null)}function am1(a,b,c,d,e,f){for(;--f>=0;){var g=b*this[a++]+c[d]+e;e=Math.floor(g/67108864),c[d++]=67108863&g}return e}function am2(a,b,c,d,e,f){for(var g=32767&b,h=b>>15;--f>=0;){var i=32767&this[a],j=this[a++]>>15,k=h*i+j*g;i=g*i+((32767&k)<<15)+c[d]+(1073741823&e),e=(i>>>30)+(k>>>15)+h*j+(e>>>30),c[d++]=1073741823&i}return e}function am3(a,b,c,d,e,f){for(var g=16383&b,h=b>>14;--f>=0;){var i=16383&this[a],j=this[a++]>>14,k=h*i+j*g;i=g*i+((16383&k)<<14)+c[d]+e,e=(i>>28)+(k>>14)+h*j,c[d++]=268435455&i}return e}function int2char(a){return BI_RM.charAt(a)}function intAt(a,b){var c=BI_RC[a.charCodeAt(b)];return null==c?-1:c}function bnpCopyTo(a){for(var b=this.t-1;b>=0;--b)a[b]=this[b];a.t=this.t,a.s=this.s}function bnpFromInt(a){this.t=1,this.s=0>a?-1:0,a>0?this[0]=a:-1>a?this[0]=a+DV:this.t=0}function nbv(a){var b=nbi();return b.fromInt(a),b}function bnpFromString(a,b){var c;if(16==b)c=4;else if(8==b)c=3;else if(256==b)c=8;else if(2==b)c=1;else if(32==b)c=5;else{if(4!=b)return void this.fromRadix(a,b);c=2}this.t=0,this.s=0;for(var d=a.length,e=!1,f=0;--d>=0;){var g=8==c?255&a[d]:intAt(a,d);0>g?"-"==a.charAt(d)&&(e=!0):(e=!1,0==f?this[this.t++]=g:f+c>this.DB?(this[this.t-1]|=(g&(1<>this.DB-f):this[this.t-1]|=g<=this.DB&&(f-=this.DB))}8==c&&0!=(128&a[0])&&(this.s=-1,f>0&&(this[this.t-1]|=(1<0&&this[this.t-1]==a;)--this.t}function bnToString(a){if(this.s<0)return"-"+this.negate().toString(a);var b;if(16==a)b=4;else if(8==a)b=3;else if(2==a)b=1;else if(32==a)b=5;else{if(4!=a)return this.toRadix(a);b=2}var c,d=(1<0)for(h>h)>0&&(e=!0,f=int2char(c));g>=0;)b>h?(c=(this[g]&(1<>(h+=this.DB-b)):(c=this[g]>>(h-=b)&d,0>=h&&(h+=this.DB,--g)),c>0&&(e=!0),e&&(f+=int2char(c));return e?f:"0"}function bnNegate(){var a=nbi();return BigInteger.ZERO.subTo(this,a),a}function bnAbs(){return this.s<0?this.negate():this}function bnCompareTo(a){var b=this.s-a.s;if(0!=b)return b;var c=this.t;if(b=c-a.t,0!=b)return this.s<0?-b:b;for(;--c>=0;)if(0!=(b=this[c]-a[c]))return b;return 0}function nbits(a){var b,c=1;return 0!=(b=a>>>16)&&(a=b,c+=16),0!=(b=a>>8)&&(a=b,c+=8),0!=(b=a>>4)&&(a=b,c+=4),0!=(b=a>>2)&&(a=b,c+=2),0!=(b=a>>1)&&(a=b,c+=1),c}function bnBitLength(){return this.t<=0?0:this.DB*(this.t-1)+nbits(this[this.t-1]^this.s&this.DM)}function bnpDLShiftTo(a,b){var c;for(c=this.t-1;c>=0;--c)b[c+a]=this[c];for(c=a-1;c>=0;--c)b[c]=0;b.t=this.t+a,b.s=this.s}function bnpDRShiftTo(a,b){for(var c=a;c=0;--c)b[c+g+1]=this[c]>>e|h,h=(this[c]&f)<=0;--c)b[c]=0;b[g]=h,b.t=this.t+g+1,b.s=this.s,b.clamp()}function bnpRShiftTo(a,b){b.s=this.s;var c=Math.floor(a/this.DB);if(c>=this.t)return void(b.t=0);var d=a%this.DB,e=this.DB-d,f=(1<>d;for(var g=c+1;g>d;d>0&&(b[this.t-c-1]|=(this.s&f)<c;)d+=this[c]-a[c],b[c++]=d&this.DM,d>>=this.DB;if(a.t>=this.DB;d+=this.s}else{for(d+=this.s;c>=this.DB;d-=a.s}b.s=0>d?-1:0,-1>d?b[c++]=this.DV+d:d>0&&(b[c++]=d),b.t=c,b.clamp()}function bnpMultiplyTo(a,b){var c=this.abs(),d=a.abs(),e=c.t;for(b.t=e+d.t;--e>=0;)b[e]=0;for(e=0;e=0;)a[c]=0;for(c=0;c=b.DV&&(a[c+b.t]-=b.DV,a[c+b.t+1]=1)}a.t>0&&(a[a.t-1]+=b.am(c,b[c],a,2*c,0,1)),a.s=0,a.clamp()}function bnpDivRemTo(a,b,c){var d=a.abs();if(!(d.t<=0)){var e=this.abs();if(e.t0?(d.lShiftTo(i,f),e.lShiftTo(i,c)):(d.copyTo(f),e.copyTo(c));var j=f.t,k=f[j-1];if(0!=k){var l=k*(1<1?f[j-2]>>this.F2:0),m=this.FV/l,n=(1<=0&&(c[c.t++]=1,c.subTo(r,c)),BigInteger.ONE.dlShiftTo(j,r),r.subTo(f,f);f.t=0;){var s=c[--p]==k?this.DM:Math.floor(c[p]*m+(c[p-1]+o)*n);if((c[p]+=f.am(0,s,c,q,0,j))0&&c.rShiftTo(i,c),0>g&&BigInteger.ZERO.subTo(c,c)}}}function bnMod(a){var b=nbi();return this.abs().divRemTo(a,null,b),this.s<0&&b.compareTo(BigInteger.ZERO)>0&&a.subTo(b,b),b}function Classic(a){this.m=a}function cConvert(a){return a.s<0||a.compareTo(this.m)>=0?a.mod(this.m):a}function cRevert(a){return a}function cReduce(a){a.divRemTo(this.m,null,a)}function cMulTo(a,b,c){a.multiplyTo(b,c),this.reduce(c)}function cSqrTo(a,b){a.squareTo(b),this.reduce(b)}function bnpInvDigit(){if(this.t<1)return 0;var a=this[0];if(0==(1&a))return 0;var b=3&a;return b=b*(2-(15&a)*b)&15,b=b*(2-(255&a)*b)&255,b=b*(2-((65535&a)*b&65535))&65535,b=b*(2-a*b%this.DV)%this.DV,b>0?this.DV-b:-b}function Montgomery(a){this.m=a,this.mp=a.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<0&&this.m.subTo(b,b),b}function montRevert(a){var b=nbi();return a.copyTo(b),this.reduce(b),b}function montReduce(a){for(;a.t<=this.mt2;)a[a.t++]=0;for(var b=0;b>15)*this.mpl&this.um)<<15)&a.DM;for(c=b+this.m.t,a[c]+=this.m.am(0,d,a,b,0,this.m.t);a[c]>=a.DV;)a[c]-=a.DV,a[++c]++}a.clamp(),a.drShiftTo(this.m.t,a),a.compareTo(this.m)>=0&&a.subTo(this.m,a)}function montSqrTo(a,b){a.squareTo(b),this.reduce(b)}function montMulTo(a,b,c){a.multiplyTo(b,c),this.reduce(c)}function bnpIsEven(){return 0==(this.t>0?1&this[0]:this.s)}function bnpExp(a,b){if(a>4294967295||1>a)return BigInteger.ONE;var c=nbi(),d=nbi(),e=b.convert(this),f=nbits(a)-1;for(e.copyTo(c);--f>=0;)if(b.sqrTo(c,d),(a&1<0)b.mulTo(d,e,c);else{var g=c;c=d,d=g}return b.revert(c)}function bnModPowInt(a,b){var c;return c=256>a||b.isEven()?new Classic(b):new Montgomery(b),this.exp(a,c)}function bnClone(){var a=nbi();return this.copyTo(a),a}function bnIntValue(){if(this.s<0){if(1==this.t)return this[0]-this.DV;if(0==this.t)return-1}else{if(1==this.t)return this[0];if(0==this.t)return 0}return(this[1]&(1<<32-this.DB)-1)<>24}function bnShortValue(){return 0==this.t?this.s:this[0]<<16>>16}function bnpChunkSize(a){return Math.floor(Math.LN2*this.DB/Math.log(a))}function bnSigNum(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1}function bnpToRadix(a){if(null==a&&(a=10),0==this.signum()||2>a||a>36)return"0";var b=this.chunkSize(a),c=Math.pow(a,b),d=nbv(c),e=nbi(),f=nbi(),g="";for(this.divRemTo(d,e,f);e.signum()>0;)g=(c+f.intValue()).toString(a).substr(1)+g,e.divRemTo(d,e,f);return f.intValue().toString(a)+g}function bnpFromRadix(a,b){this.fromInt(0),null==b&&(b=10);for(var c=this.chunkSize(b),d=Math.pow(b,c),e=!1,f=0,g=0,h=0;hi?"-"==a.charAt(h)&&0==this.signum()&&(e=!0):(g=b*g+i,++f>=c&&(this.dMultiply(d),this.dAddOffset(g,0),f=0,g=0))}f>0&&(this.dMultiply(Math.pow(b,f)),this.dAddOffset(g,0)),e&&BigInteger.ZERO.subTo(this,this)}function bnpFromNumber(a,b,c){if("number"==typeof b)if(2>a)this.fromInt(1);else for(this.fromNumber(a,c),this.testBit(a-1)||this.bitwiseTo(BigInteger.ONE.shiftLeft(a-1),op_or,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(b);)this.dAddOffset(2,0),this.bitLength()>a&&this.subTo(BigInteger.ONE.shiftLeft(a-1),this);else{var d=new Array,e=7&a;d.length=(a>>3)+1,b.nextBytes(d),e>0?d[0]&=(1<0)for(d>d)!=(this.s&this.DM)>>d&&(b[e++]=c|this.s<=0;)8>d?(c=(this[a]&(1<>(d+=this.DB-8)):(c=this[a]>>(d-=8)&255,0>=d&&(d+=this.DB,--a)),0!=(128&c)&&(c|=-256),0==e&&(128&this.s)!=(128&c)&&++e,(e>0||c!=this.s)&&(b[e++]=c);return b}function bnEquals(a){return 0==this.compareTo(a)}function bnMin(a){return this.compareTo(a)<0?this:a}function bnMax(a){return this.compareTo(a)>0?this:a}function bnpBitwiseTo(a,b,c){var d,e,f=Math.min(a.t,this.t);for(d=0;f>d;++d)c[d]=b(this[d],a[d]);if(a.ta?this.rShiftTo(-a,b):this.lShiftTo(a,b),b}function bnShiftRight(a){var b=nbi();return 0>a?this.lShiftTo(-a,b):this.rShiftTo(a,b),b}function lbit(a){if(0==a)return-1;var b=0;return 0==(65535&a)&&(a>>=16,b+=16),0==(255&a)&&(a>>=8,b+=8),0==(15&a)&&(a>>=4,b+=4),0==(3&a)&&(a>>=2,b+=2),0==(1&a)&&++b,b}function bnGetLowestSetBit(){for(var a=0;a=this.t?0!=this.s:0!=(this[b]&1<c;)d+=this[c]+a[c],b[c++]=d&this.DM,d>>=this.DB;if(a.t>=this.DB;d+=this.s}else{for(d+=this.s;c>=this.DB;d+=a.s}b.s=0>d?-1:0,d>0?b[c++]=d:-1>d&&(b[c++]=this.DV+d),b.t=c,b.clamp()}function bnAdd(a){var b=nbi();return this.addTo(a,b),b}function bnSubtract(a){var b=nbi();return this.subTo(a,b),b}function bnMultiply(a){var b=nbi();return this.multiplyTo(a,b),b}function bnSquare(){var a=nbi();return this.squareTo(a),a}function bnDivide(a){var b=nbi();return this.divRemTo(a,b,null),b}function bnRemainder(a){var b=nbi();return this.divRemTo(a,null,b),b}function bnDivideAndRemainder(a){var b=nbi(),c=nbi();return this.divRemTo(a,b,c),new Array(b,c)}function bnpDMultiply(a){this[this.t]=this.am(0,a-1,this,0,0,this.t),++this.t,this.clamp()}function bnpDAddOffset(a,b){if(0!=a){for(;this.t<=b;)this[this.t++]=0;for(this[b]+=a;this[b]>=this.DV;)this[b]-=this.DV,++b>=this.t&&(this[this.t++]=0),++this[b]}}function NullExp(){}function nNop(a){return a}function nMulTo(a,b,c){a.multiplyTo(b,c)}function nSqrTo(a,b){a.squareTo(b)}function bnPow(a){return this.exp(a,new NullExp)}function bnpMultiplyLowerTo(a,b,c){var d=Math.min(this.t+a.t,b);for(c.s=0,c.t=d;d>0;)c[--d]=0;var e;for(e=c.t-this.t;e>d;++d)c[d+this.t]=this.am(0,a[d],c,d,0,this.t);for(e=Math.min(a.t,b);e>d;++d)this.am(0,a[d],c,d,0,b-d);c.clamp()}function bnpMultiplyUpperTo(a,b,c){--b;var d=c.t=this.t+a.t-b;for(c.s=0;--d>=0;)c[d]=0;for(d=Math.max(b-this.t,0);d2*this.m.t)return a.mod(this.m);if(a.compareTo(this.m)<0)return a;var b=nbi();return a.copyTo(b),this.reduce(b),b}function barrettRevert(a){return a}function barrettReduce(a){for(a.drShiftTo(this.m.t-1,this.r2),a.t>this.m.t+1&&(a.t=this.m.t+1,a.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);a.compareTo(this.r2)<0;)a.dAddOffset(1,this.m.t+1);for(a.subTo(this.r2,a);a.compareTo(this.m)>=0;)a.subTo(this.m,a)}function barrettSqrTo(a,b){a.squareTo(b),this.reduce(b)}function barrettMulTo(a,b,c){a.multiplyTo(b,c),this.reduce(c)}function bnModPow(a,b){var c,d,e=a.bitLength(),f=nbv(1);if(0>=e)return f;c=18>e?1:48>e?3:144>e?4:768>e?5:6,d=8>e?new Classic(b):b.isEven()?new Barrett(b):new Montgomery(b);var g=new Array,h=3,i=c-1,j=(1<1){var k=nbi();for(d.sqrTo(g[1],k);j>=h;)g[h]=nbi(),d.mulTo(k,g[h-2],g[h]),h+=2}var l,m,n=a.t-1,o=!0,p=nbi();for(e=nbits(a[n])-1;n>=0;){for(e>=i?l=a[n]>>e-i&j:(l=(a[n]&(1<0&&(l|=a[n-1]>>this.DB+e-i)),h=c;0==(1&l);)l>>=1,--h;if((e-=h)<0&&(e+=this.DB,--n),o)g[l].copyTo(f),o=!1;else{for(;h>1;)d.sqrTo(f,p),d.sqrTo(p,f),h-=2;h>0?d.sqrTo(f,p):(m=f,f=p,p=m),d.mulTo(p,g[l],f)}for(;n>=0&&0==(a[n]&1<f)return b;for(f>e&&(f=e),f>0&&(b.rShiftTo(f,b),c.rShiftTo(f,c));b.signum()>0;)(e=b.getLowestSetBit())>0&&b.rShiftTo(e,b),(e=c.getLowestSetBit())>0&&c.rShiftTo(e,c),b.compareTo(c)>=0?(b.subTo(c,b),b.rShiftTo(1,b)):(c.subTo(b,c),c.rShiftTo(1,c));return f>0&&c.lShiftTo(f,c),c}function bnpModInt(a){if(0>=a)return 0;var b=this.DV%a,c=this.s<0?a-1:0;if(this.t>0)if(0==b)c=this[0]%a;else for(var d=this.t-1;d>=0;--d)c=(b*c+this[d])%a;return c}function bnModInverse(a){var b=a.isEven();if(this.isEven()&&b||0==a.signum())return BigInteger.ZERO;for(var c=a.clone(),d=this.clone(),e=nbv(1),f=nbv(0),g=nbv(0),h=nbv(1);0!=c.signum();){for(;c.isEven();)c.rShiftTo(1,c),b?(e.isEven()&&f.isEven()||(e.addTo(this,e),f.subTo(a,f)),e.rShiftTo(1,e)):f.isEven()||f.subTo(a,f),f.rShiftTo(1,f);for(;d.isEven();)d.rShiftTo(1,d),b?(g.isEven()&&h.isEven()||(g.addTo(this,g),h.subTo(a,h)),g.rShiftTo(1,g)):h.isEven()||h.subTo(a,h),h.rShiftTo(1,h);c.compareTo(d)>=0?(c.subTo(d,c),b&&e.subTo(g,e),f.subTo(h,f)):(d.subTo(c,d),b&&g.subTo(e,g),h.subTo(f,h))}return 0!=d.compareTo(BigInteger.ONE)?BigInteger.ZERO:h.compareTo(a)>=0?h.subtract(a):h.signum()<0?(h.addTo(a,h),h.signum()<0?h.add(a):h):h}function bnIsProbablePrime(a){var b,c=this.abs();if(1==c.t&&c[0]<=lowprimes[lowprimes.length-1]){for(b=0;bd;)d*=lowprimes[e++];for(d=c.modInt(d);e>b;)if(d%lowprimes[b++]==0)return!1}return c.millerRabin(a)}function bnpMillerRabin(a){var b=this.subtract(BigInteger.ONE),c=b.getLowestSetBit();if(0>=c)return!1;var d=b.shiftRight(c);a=a+1>>1,a>lowprimes.length&&(a=lowprimes.length);for(var e=nbi(),f=0;a>f;++f){e.fromInt(lowprimes[Math.floor(Math.random()*lowprimes.length)]);var g=e.modPow(d,this);if(0!=g.compareTo(BigInteger.ONE)&&0!=g.compareTo(b)){for(var h=1;h++b;++b)this.S[b]=b;for(c=0,b=0;256>b;++b)c=c+this.S[b]+a[b%a.length]&255,d=this.S[b],this.S[b]=this.S[c],this.S[c]=d;this.i=0,this.j=0}function ARC4next(){var a;return this.i=this.i+1&255,this.j=this.j+this.S[this.i]&255,a=this.S[this.i],this.S[this.i]=this.S[this.j],this.S[this.j]=a,this.S[a+this.S[this.i]&255]}function prng_newstate(){return new Arcfour}function rng_get_byte(){if(null==rng_state){for(rng_state=prng_newstate();rng_psize>rng_pptr;){var a=Math.floor(65536*Math.random());rng_pool[rng_pptr++]=255&a}for(rng_state.init(rng_pool),rng_pptr=0;rng_pptra?"0"+a.toString(16):a.toString(16)}function pkcs1pad2(a,b){if(b=0&&b>0;){var e=a.charCodeAt(d--);128>e?c[--b]=e:e>127&&2048>e?(c[--b]=63&e|128,c[--b]=e>>6|192):(c[--b]=63&e|128,c[--b]=e>>6&63|128,c[--b]=e>>12|224)}c[--b]=0;for(var f=new SecureRandom,g=new Array;b>2;){for(g[0]=0;0==g[0];)f.nextBytes(g);c[--b]=g[0]}return c[--b]=2,c[--b]=0,new BigInteger(c)}function RSAKey(){this.n=null,this.e=0,this.d=null,this.p=null,this.q=null,this.dmp1=null,this.dmq1=null,this.coeff=null}function RSASetPublic(a,b){null!=a&&null!=b&&a.length>0&&b.length>0?(this.n=parseBigInt(a,16),this.e=parseInt(b,16)):console.error("Invalid RSA public key")}function RSADoPublic(a){return a.modPowInt(this.e,this.n)}function RSAEncrypt(a){var b=pkcs1pad2(a,this.n.bitLength()+7>>3);if(null==b)return null;var c=this.doPublic(b);if(null==c)return null;var d=c.toString(16);return 0==(1&d.length)?d:"0"+d}function pkcs1unpad2(a,b){for(var c=a.toByteArray(),d=0;d=c.length)return null;for(var e="";++df?e+=String.fromCharCode(f):f>191&&224>f?(e+=String.fromCharCode((31&f)<<6|63&c[d+1]),++d):(e+=String.fromCharCode((15&f)<<12|(63&c[d+1])<<6|63&c[d+2]),d+=2)}return e}function RSASetPrivate(a,b,c){null!=a&&null!=b&&a.length>0&&b.length>0?(this.n=parseBigInt(a,16),this.e=parseInt(b,16),this.d=parseBigInt(c,16)):console.error("Invalid RSA private key")}function RSASetPrivateEx(a,b,c,d,e,f,g,h){null!=a&&null!=b&&a.length>0&&b.length>0?(this.n=parseBigInt(a,16),this.e=parseInt(b,16),this.d=parseBigInt(c,16),this.p=parseBigInt(d,16),this.q=parseBigInt(e,16),this.dmp1=parseBigInt(f,16),this.dmq1=parseBigInt(g,16),this.coeff=parseBigInt(h,16)):console.error("Invalid RSA private key")}function RSAGenerate(a,b){var c=new SecureRandom,d=a>>1;this.e=parseInt(b,16);for(var e=new BigInteger(b,16);;){for(;this.p=new BigInteger(a-d,1,c),0!=this.p.subtract(BigInteger.ONE).gcd(e).compareTo(BigInteger.ONE)||!this.p.isProbablePrime(10););for(;this.q=new BigInteger(d,1,c),0!=this.q.subtract(BigInteger.ONE).gcd(e).compareTo(BigInteger.ONE)||!this.q.isProbablePrime(10););if(this.p.compareTo(this.q)<=0){var f=this.p;this.p=this.q,this.q=f}var g=this.p.subtract(BigInteger.ONE),h=this.q.subtract(BigInteger.ONE),i=g.multiply(h);if(0==i.gcd(e).compareTo(BigInteger.ONE)){this.n=this.p.multiply(this.q),this.d=e.modInverse(i),this.dmp1=this.d.mod(g),this.dmq1=this.d.mod(h),this.coeff=this.q.modInverse(this.p);break}}}function RSADoPrivate(a){if(null==this.p||null==this.q)return a.modPow(this.d,this.n);for(var b=a.mod(this.p).modPow(this.dmp1,this.p),c=a.mod(this.q).modPow(this.dmq1,this.q);b.compareTo(c)<0;)b=b.add(this.p);return b.subtract(c).multiply(this.coeff).mod(this.p).multiply(this.q).add(c)}function RSADecrypt(a){var b=parseBigInt(a,16),c=this.doPrivate(b);return null==c?null:pkcs1unpad2(c,this.n.bitLength()+7>>3)}function hex2b64(a){var b,c,d="";for(b=0;b+3<=a.length;b+=3)c=parseInt(a.substring(b,b+3),16),d+=b64map.charAt(c>>6)+b64map.charAt(63&c);for(b+1==a.length?(c=parseInt(a.substring(b,b+1),16),d+=b64map.charAt(c<<2)):b+2==a.length&&(c=parseInt(a.substring(b,b+2),16),d+=b64map.charAt(c>>2)+b64map.charAt((3&c)<<4));(3&d.length)>0;)d+=b64pad;return d}function b64tohex(a){var b,c,d="",e=0;for(b=0;b>2),c=3&v,e=1):1==e?(d+=int2char(c<<2|v>>4),c=15&v,e=2):2==e?(d+=int2char(c),d+=int2char(v>>2),c=3&v,e=3):(d+=int2char(c<<2|v>>4),d+=int2char(15&v),e=0));return 1==e&&(d+=int2char(c<<2)),d}function b64toBA(a){var b,c=b64tohex(a),d=new Array;for(b=0;2*b=vv;++vv)BI_RC[rr++]=vv;for(rr="a".charCodeAt(0),vv=10;36>vv;++vv)BI_RC[rr++]=vv;for(rr="A".charCodeAt(0),vv=10;36>vv;++vv)BI_RC[rr++]=vv;Classic.prototype.convert=cConvert,Classic.prototype.revert=cRevert,Classic.prototype.reduce=cReduce,Classic.prototype.mulTo=cMulTo,Classic.prototype.sqrTo=cSqrTo,Montgomery.prototype.convert=montConvert,Montgomery.prototype.revert=montRevert,Montgomery.prototype.reduce=montReduce,Montgomery.prototype.mulTo=montMulTo,Montgomery.prototype.sqrTo=montSqrTo,BigInteger.prototype.copyTo=bnpCopyTo,BigInteger.prototype.fromInt=bnpFromInt,BigInteger.prototype.fromString=bnpFromString,BigInteger.prototype.clamp=bnpClamp,BigInteger.prototype.dlShiftTo=bnpDLShiftTo,BigInteger.prototype.drShiftTo=bnpDRShiftTo,BigInteger.prototype.lShiftTo=bnpLShiftTo,BigInteger.prototype.rShiftTo=bnpRShiftTo,BigInteger.prototype.subTo=bnpSubTo,BigInteger.prototype.multiplyTo=bnpMultiplyTo,BigInteger.prototype.squareTo=bnpSquareTo,BigInteger.prototype.divRemTo=bnpDivRemTo,BigInteger.prototype.invDigit=bnpInvDigit,BigInteger.prototype.isEven=bnpIsEven,BigInteger.prototype.exp=bnpExp,BigInteger.prototype.toString=bnToString,BigInteger.prototype.negate=bnNegate,BigInteger.prototype.abs=bnAbs,BigInteger.prototype.compareTo=bnCompareTo,BigInteger.prototype.bitLength=bnBitLength,BigInteger.prototype.mod=bnMod,BigInteger.prototype.modPowInt=bnModPowInt,BigInteger.ZERO=nbv(0),BigInteger.ONE=nbv(1),NullExp.prototype.convert=nNop,NullExp.prototype.revert=nNop,NullExp.prototype.mulTo=nMulTo,NullExp.prototype.sqrTo=nSqrTo,Barrett.prototype.convert=barrettConvert,Barrett.prototype.revert=barrettRevert,Barrett.prototype.reduce=barrettReduce,Barrett.prototype.mulTo=barrettMulTo,Barrett.prototype.sqrTo=barrettSqrTo;var lowprimes=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],lplim=(1<<26)/lowprimes[lowprimes.length-1];BigInteger.prototype.chunkSize=bnpChunkSize,BigInteger.prototype.toRadix=bnpToRadix,BigInteger.prototype.fromRadix=bnpFromRadix,BigInteger.prototype.fromNumber=bnpFromNumber,BigInteger.prototype.bitwiseTo=bnpBitwiseTo,BigInteger.prototype.changeBit=bnpChangeBit,BigInteger.prototype.addTo=bnpAddTo,BigInteger.prototype.dMultiply=bnpDMultiply,BigInteger.prototype.dAddOffset=bnpDAddOffset,BigInteger.prototype.multiplyLowerTo=bnpMultiplyLowerTo,BigInteger.prototype.multiplyUpperTo=bnpMultiplyUpperTo,BigInteger.prototype.modInt=bnpModInt,BigInteger.prototype.millerRabin=bnpMillerRabin,BigInteger.prototype.clone=bnClone,BigInteger.prototype.intValue=bnIntValue,BigInteger.prototype.byteValue=bnByteValue,BigInteger.prototype.shortValue=bnShortValue,BigInteger.prototype.signum=bnSigNum,BigInteger.prototype.toByteArray=bnToByteArray,BigInteger.prototype.equals=bnEquals,BigInteger.prototype.min=bnMin,BigInteger.prototype.max=bnMax,BigInteger.prototype.and=bnAnd,BigInteger.prototype.or=bnOr,BigInteger.prototype.xor=bnXor,BigInteger.prototype.andNot=bnAndNot,BigInteger.prototype.not=bnNot,BigInteger.prototype.shiftLeft=bnShiftLeft,BigInteger.prototype.shiftRight=bnShiftRight,BigInteger.prototype.getLowestSetBit=bnGetLowestSetBit,BigInteger.prototype.bitCount=bnBitCount,BigInteger.prototype.testBit=bnTestBit,BigInteger.prototype.setBit=bnSetBit,BigInteger.prototype.clearBit=bnClearBit,BigInteger.prototype.flipBit=bnFlipBit,BigInteger.prototype.add=bnAdd,BigInteger.prototype.subtract=bnSubtract,BigInteger.prototype.multiply=bnMultiply,BigInteger.prototype.divide=bnDivide,BigInteger.prototype.remainder=bnRemainder,BigInteger.prototype.divideAndRemainder=bnDivideAndRemainder,BigInteger.prototype.modPow=bnModPow,BigInteger.prototype.modInverse=bnModInverse,BigInteger.prototype.pow=bnPow,BigInteger.prototype.gcd=bnGCD,BigInteger.prototype.isProbablePrime=bnIsProbablePrime,BigInteger.prototype.square=bnSquare,Arcfour.prototype.init=ARC4init,Arcfour.prototype.next=ARC4next;var rng_psize=256,rng_state,rng_pool,rng_pptr;if(null==rng_pool){rng_pool=new Array,rng_pptr=0;var t;if(window.crypto&&window.crypto.getRandomValues){var z=new Uint32Array(256);for(window.crypto.getRandomValues(z),t=0;t=256||rng_pptr>=rng_psize)return void(window.removeEventListener?window.removeEventListener("mousemove",onMouseMoveListener):window.detachEvent&&window.detachEvent("onmousemove",onMouseMoveListener));this.count+=1;var b=a.x+a.y;rng_pool[rng_pptr++]=255&b};window.addEventListener?window.addEventListener("mousemove",onMouseMoveListener):window.attachEvent&&window.attachEvent("onmousemove",onMouseMoveListener)}SecureRandom.prototype.nextBytes=rng_get_bytes,RSAKey.prototype.doPublic=RSADoPublic,RSAKey.prototype.setPublic=RSASetPublic,RSAKey.prototype.encrypt=RSAEncrypt,RSAKey.prototype.doPrivate=RSADoPrivate,RSAKey.prototype.setPrivate=RSASetPrivate,RSAKey.prototype.setPrivateEx=RSASetPrivateEx,RSAKey.prototype.generate=RSAGenerate,RSAKey.prototype.decrypt=RSADecrypt,function(){var a=function(a,b,c){var d=new SecureRandom,e=a>>1;this.e=parseInt(b,16);var f=new BigInteger(b,16),g=this,h=function(){var b=function(){if(g.p.compareTo(g.q)<=0){var a=g.p;g.p=g.q,g.q=a}var b=g.p.subtract(BigInteger.ONE),d=g.q.subtract(BigInteger.ONE),e=b.multiply(d);0==e.gcd(f).compareTo(BigInteger.ONE)?(g.n=g.p.multiply(g.q),g.d=f.modInverse(e),g.dmp1=g.d.mod(b),g.dmq1=g.d.mod(d),g.coeff=g.q.modInverse(g.p),setTimeout(function(){c()},0)):setTimeout(h,0)},i=function(){g.q=nbi(),g.q.fromNumberAsync(e,1,d,function(){g.q.subtract(BigInteger.ONE).gcda(f,function(a){0==a.compareTo(BigInteger.ONE)&&g.q.isProbablePrime(10)?setTimeout(b,0):setTimeout(i,0)})})},j=function(){g.p=nbi(),g.p.fromNumberAsync(a-e,1,d,function(){g.p.subtract(BigInteger.ONE).gcda(f,function(a){0==a.compareTo(BigInteger.ONE)&&g.p.isProbablePrime(10)?setTimeout(i,0):setTimeout(j,0)})})};setTimeout(j,0)};setTimeout(h,0)};RSAKey.prototype.generateAsync=a;var b=function(a,b){var c=this.s<0?this.negate():this.clone(),d=a.s<0?a.negate():a.clone();if(c.compareTo(d)<0){var e=c;c=d,d=e}var f=c.getLowestSetBit(),g=d.getLowestSetBit();if(0>g)return void b(c);g>f&&(g=f),g>0&&(c.rShiftTo(g,c),d.rShiftTo(g,d));var h=function(){(f=c.getLowestSetBit())>0&&c.rShiftTo(f,c),(f=d.getLowestSetBit())>0&&d.rShiftTo(f,d),c.compareTo(d)>=0?(c.subTo(d,c),c.rShiftTo(1,c)):(d.subTo(c,d),d.rShiftTo(1,d)),c.signum()>0?setTimeout(h,0):(g>0&&d.lShiftTo(g,d),setTimeout(function(){b(d)},0))};setTimeout(h,10)};BigInteger.prototype.gcda=b;var c=function(a,b,c,d){if("number"==typeof b)if(2>a)this.fromInt(1);else{this.fromNumber(a,c),this.testBit(a-1)||this.bitwiseTo(BigInteger.ONE.shiftLeft(a-1),op_or,this),this.isEven()&&this.dAddOffset(1,0);var e=this,f=function(){e.dAddOffset(2,0),e.bitLength()>a&&e.subTo(BigInteger.ONE.shiftLeft(a-1),e),e.isProbablePrime(b)?setTimeout(function(){d()},0):setTimeout(f,0)};setTimeout(f,0)}else{var g=new Array,h=7&a;g.length=(a>>3)+1,b.nextBytes(g),h>0?g[0]&=(1<f;f++)e+="f";var g=new BigInteger(e,16),h=g.xor(a).add(BigInteger.ONE);b=h.toString(16).replace(/^-/,"")}return b},this.getPEMStringFromHex=function(a,b){var c=CryptoJS.enc.Hex.parse(a),d=CryptoJS.enc.Base64.stringify(c),e=d.replace(/(.{64})/g,"$1\r\n");return e=e.replace(/\r\n$/,""),"-----BEGIN "+b+"-----\r\n"+e+"\r\n-----END "+b+"-----\r\n"}},KJUR.asn1.ASN1Object=function(){var a="";this.getLengthHexFromValue=function(){if("undefined"==typeof this.hV||null==this.hV)throw"this.hV is null or undefined.";if(this.hV.length%2==1)throw"value hex must be even length: n="+a.length+",v="+this.hV;var b=this.hV.length/2,c=b.toString(16);if(c.length%2==1&&(c="0"+c),128>b)return c;var d=c.length/2;if(d>15)throw"ASN.1 length too long to represent by 8x: n = "+b.toString(16);var e=128+d;return e.toString(16)+c},this.getEncodedHex=function(){return(null==this.hTLV||this.isModified)&&(this.hV=this.getFreshValueHex(),this.hL=this.getLengthHexFromValue(),this.hTLV=this.hT+this.hL+this.hV,this.isModified=!1),this.hTLV},this.getValueHex=function(){return this.getEncodedHex(),this.hV},this.getFreshValueHex=function(){return""}},KJUR.asn1.DERAbstractString=function(a){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);this.getString=function(){return this.s},this.setString=function(a){this.hTLV=null,this.isModified=!0,this.s=a,this.hV=stohex(this.s)},this.setStringHex=function(a){this.hTLV=null,this.isModified=!0,this.s=null,this.hV=a},this.getFreshValueHex=function(){return this.hV},"undefined"!=typeof a&&("undefined"!=typeof a.str?this.setString(a.str):"undefined"!=typeof a.hex&&this.setStringHex(a.hex))},JSX.extend(KJUR.asn1.DERAbstractString,KJUR.asn1.ASN1Object),KJUR.asn1.DERAbstractTime=function(){KJUR.asn1.DERAbstractTime.superclass.constructor.call(this);this.localDateToUTC=function(a){utc=a.getTime()+6e4*a.getTimezoneOffset();var b=new Date(utc);return b},this.formatDate=function(a,b){var c=this.zeroPadding,d=this.localDateToUTC(a),e=String(d.getFullYear());"utc"==b&&(e=e.substr(2,2));var f=c(String(d.getMonth()+1),2),g=c(String(d.getDate()),2),h=c(String(d.getHours()),2),i=c(String(d.getMinutes()),2),j=c(String(d.getSeconds()),2);return e+f+g+h+i+j+"Z"},this.zeroPadding=function(a,b){return a.length>=b?a:new Array(b-a.length+1).join("0")+a},this.getString=function(){return this.s},this.setString=function(a){this.hTLV=null,this.isModified=!0,this.s=a,this.hV=stohex(this.s)},this.setByDateValue=function(a,b,c,d,e,f){var g=new Date(Date.UTC(a,b-1,c,d,e,f,0));this.setByDate(g)},this.getFreshValueHex=function(){return this.hV}},JSX.extend(KJUR.asn1.DERAbstractTime,KJUR.asn1.ASN1Object),KJUR.asn1.DERAbstractStructured=function(a){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);this.setByASN1ObjectArray=function(a){this.hTLV=null,this.isModified=!0,this.asn1Array=a},this.appendASN1Object=function(a){this.hTLV=null,this.isModified=!0,this.asn1Array.push(a)},this.asn1Array=new Array,"undefined"!=typeof a&&"undefined"!=typeof a.array&&(this.asn1Array=a.array)},JSX.extend(KJUR.asn1.DERAbstractStructured,KJUR.asn1.ASN1Object),KJUR.asn1.DERBoolean=function(){KJUR.asn1.DERBoolean.superclass.constructor.call(this),this.hT="01",this.hTLV="0101ff"},JSX.extend(KJUR.asn1.DERBoolean,KJUR.asn1.ASN1Object),KJUR.asn1.DERInteger=function(a){KJUR.asn1.DERInteger.superclass.constructor.call(this),this.hT="02",this.setByBigInteger=function(a){this.hTLV=null,this.isModified=!0,this.hV=KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(a)},this.setByInteger=function(a){var b=new BigInteger(String(a),10);this.setByBigInteger(b)},this.setValueHex=function(a){this.hV=a},this.getFreshValueHex=function(){return this.hV},"undefined"!=typeof a&&("undefined"!=typeof a.bigint?this.setByBigInteger(a.bigint):"undefined"!=typeof a["int"]?this.setByInteger(a["int"]):"undefined"!=typeof a.hex&&this.setValueHex(a.hex))},JSX.extend(KJUR.asn1.DERInteger,KJUR.asn1.ASN1Object),KJUR.asn1.DERBitString=function(a){KJUR.asn1.DERBitString.superclass.constructor.call(this),this.hT="03",this.setHexValueIncludingUnusedBits=function(a){this.hTLV=null,this.isModified=!0,this.hV=a},this.setUnusedBitsAndHexValue=function(a,b){if(0>a||a>7)throw"unused bits shall be from 0 to 7: u = "+a;var c="0"+a;this.hTLV=null,this.isModified=!0,this.hV=c+b},this.setByBinaryString=function(a){a=a.replace(/0+$/,"");var b=8-a.length%8;8==b&&(b=0);for(var c=0;b>=c;c++)a+="0";for(var d="",c=0;cc;c++)b[c]=!1;return b},this.getFreshValueHex=function(){return this.hV},"undefined"!=typeof a&&("undefined"!=typeof a.hex?this.setHexValueIncludingUnusedBits(a.hex):"undefined"!=typeof a.bin?this.setByBinaryString(a.bin):"undefined"!=typeof a.array&&this.setByBooleanArray(a.array))},JSX.extend(KJUR.asn1.DERBitString,KJUR.asn1.ASN1Object),KJUR.asn1.DEROctetString=function(a){KJUR.asn1.DEROctetString.superclass.constructor.call(this,a),this.hT="04"},JSX.extend(KJUR.asn1.DEROctetString,KJUR.asn1.DERAbstractString),KJUR.asn1.DERNull=function(){KJUR.asn1.DERNull.superclass.constructor.call(this),this.hT="05",this.hTLV="0500"},JSX.extend(KJUR.asn1.DERNull,KJUR.asn1.ASN1Object),KJUR.asn1.DERObjectIdentifier=function(a){var b=function(a){var b=a.toString(16);return 1==b.length&&(b="0"+b),b},c=function(a){var c="",d=new BigInteger(a,10),e=d.toString(2),f=7-e.length%7;7==f&&(f=0);for(var g="",h=0;f>h;h++)g+="0";e=g+e;for(var h=0;hd;++d)b[e.charAt(d)]=d;for(e=e.toLowerCase(),d=10;16>d;++d)b[e.charAt(d)]=d;for(d=0;d=2?(g[g.length]=h,h=0,i=0):h<<=4}}if(i)throw"Hex encoding incomplete: 4 bits missing";return g},window.Hex=c}(),function(a){"use strict";var b,c={};c.decode=function(c){var d;if(b===a){var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",f="= \f\n\r \u2028\u2029";for(b=[],d=0;64>d;++d)b[e.charAt(d)]=d;for(d=0;d=4?(g[g.length]=h>>16,g[g.length]=h>>8&255,g[g.length]=255&h,h=0,i=0):h<<=6}}switch(i){case 1:throw"Base64 encoding incomplete: at least 2 bits missing";case 2:g[g.length]=h>>10;break;case 3:g[g.length]=h>>16,g[g.length]=h>>8&255}return g},c.re=/-----BEGIN [^-]+-----([A-Za-z0-9+\/=\s]+)-----END [^-]+-----|begin-base64[^\n]+\n([A-Za-z0-9+\/=\s]+)====/,c.unarmor=function(a){var b=c.re.exec(a);if(b)if(b[1])a=b[1];else{if(!b[2])throw"RegExp out of sync";a=b[2]}return c.decode(a)},window.Base64=c}(),function(a){"use strict";function b(a,c){a instanceof b?(this.enc=a.enc,this.pos=a.pos):(this.enc=a,this.pos=c)}function c(a,b,c,d,e){this.stream=a,this.header=b,this.length=c,this.tag=d,this.sub=e}var d=100,e="…",f={tag:function(a,b){var c=document.createElement(a);return c.className=b,c},text:function(a){return document.createTextNode(a)}};b.prototype.get=function(b){if(b===a&&(b=this.pos++),b>=this.enc.length)throw"Requesting byte offset "+b+" on a stream of length "+this.enc.length;return this.enc[b]},b.prototype.hexDigits="0123456789ABCDEF",b.prototype.hexByte=function(a){return this.hexDigits.charAt(a>>4&15)+this.hexDigits.charAt(15&a)},b.prototype.hexDump=function(a,b,c){for(var d="",e=a;b>e;++e)if(d+=this.hexByte(this.get(e)),c!==!0)switch(15&e){case 7:d+=" ";break;case 15:d+="\n";break;default:d+=" "}return d},b.prototype.parseStringISO=function(a,b){for(var c="",d=a;b>d;++d)c+=String.fromCharCode(this.get(d));return c},b.prototype.parseStringUTF=function(a,b){for(var c="",d=a;b>d;){var e=this.get(d++);c+=String.fromCharCode(128>e?e:e>191&&224>e?(31&e)<<6|63&this.get(d++):(15&e)<<12|(63&this.get(d++))<<6|63&this.get(d++))}return c},b.prototype.parseStringBMP=function(a,b){for(var c="",d=a;b>d;d+=2){var e=this.get(d),f=this.get(d+1);c+=String.fromCharCode((e<<8)+f)}return c},b.prototype.reTime=/^((?:1[89]|2\d)?\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|[-+](?:[0]\d|1[0-2])([0-5]\d)?)?$/,b.prototype.parseTime=function(a,b){var c=this.parseStringISO(a,b),d=this.reTime.exec(c);return d?(c=d[1]+"-"+d[2]+"-"+d[3]+" "+d[4],d[5]&&(c+=":"+d[5],d[6]&&(c+=":"+d[6],d[7]&&(c+="."+d[7]))),d[8]&&(c+=" UTC","Z"!=d[8]&&(c+=d[8],d[9]&&(c+=":"+d[9]))),c):"Unrecognized time: "+c},b.prototype.parseInteger=function(a,b){var c=b-a;if(c>4){c<<=3;var d=this.get(a);if(0===d)c-=8;else for(;128>d;)d<<=1,--c;return"("+c+" bit)"}for(var e=0,f=a;b>f;++f)e=e<<8|this.get(f);return e},b.prototype.parseBitString=function(a,b){var c=this.get(a),d=(b-a-1<<3)-c,e="("+d+" bit)";if(20>=d){var f=c;e+=" ";for(var g=b-1;g>a;--g){for(var h=this.get(g),i=f;8>i;++i)e+=h>>i&1?"1":"0";f=0}}return e},b.prototype.parseOctetString=function(a,b){var c=b-a,f="("+c+" byte) ";c>d&&(b=a+d);for(var g=a;b>g;++g)f+=this.hexByte(this.get(g));return c>d&&(f+=e),f},b.prototype.parseOID=function(a,b){for(var c="",d=0,e=0,f=a;b>f;++f){var g=this.get(f);if(d=d<<7|127&g,e+=7,!(128&g)){if(""===c){var h=80>d?40>d?0:1:2;c=h+"."+(d-40*h)}else c+="."+(e>=31?"bigint":d);d=e=0}}return c},c.prototype.typeName=function(){if(this.tag===a)return"unknown";var b=this.tag>>6,c=(this.tag>>5&1,31&this.tag);switch(b){case 0:switch(c){case 0:return"EOC";case 1:return"BOOLEAN";case 2:return"INTEGER";case 3:return"BIT_STRING";case 4:return"OCTET_STRING";case 5:return"NULL";case 6:return"OBJECT_IDENTIFIER";case 7:return"ObjectDescriptor";case 8:return"EXTERNAL";case 9:return"REAL";case 10:return"ENUMERATED";case 11:return"EMBEDDED_PDV";case 12:return"UTF8String";case 16:return"SEQUENCE";case 17:return"SET";case 18:return"NumericString";case 19:return"PrintableString";case 20:return"TeletexString";case 21:return"VideotexString";case 22:return"IA5String";case 23:return"UTCTime";case 24:return"GeneralizedTime";case 25:return"GraphicString";case 26:return"VisibleString";case 27:return"GeneralString";case 28:return"UniversalString";case 30:return"BMPString";default:return"Universal_"+c.toString(16)}case 1:return"Application_"+c.toString(16);case 2:return"["+c+"]";case 3:return"Private_"+c.toString(16)}},c.prototype.reSeemsASCII=/^[ -~]+$/,c.prototype.content=function(){if(this.tag===a)return null;var b=this.tag>>6,c=31&this.tag,f=this.posContent(),g=Math.abs(this.length);if(0!==b){if(null!==this.sub)return"("+this.sub.length+" elem)";var h=this.stream.parseStringISO(f,f+Math.min(g,d));return this.reSeemsASCII.test(h)?h.substring(0,2*d)+(h.length>2*d?e:""):this.stream.parseOctetString(f,f+g)}switch(c){case 1:return 0===this.stream.get(f)?"false":"true";case 2:return this.stream.parseInteger(f,f+g);case 3:return this.sub?"("+this.sub.length+" elem)":this.stream.parseBitString(f,f+g);case 4:return this.sub?"("+this.sub.length+" elem)":this.stream.parseOctetString(f,f+g);case 6:return this.stream.parseOID(f,f+g);case 16:case 17:return"("+this.sub.length+" elem)";case 12:return this.stream.parseStringUTF(f,f+g);case 18:case 19:case 20:case 21:case 22:case 26:return this.stream.parseStringISO(f,f+g);case 30:return this.stream.parseStringBMP(f,f+g);case 23:case 24:return this.stream.parseTime(f,f+g)}return null},c.prototype.toString=function(){return this.typeName()+"@"+this.stream.pos+"[header:"+this.header+",length:"+this.length+",sub:"+(null===this.sub?"null":this.sub.length)+"]"},c.prototype.print=function(b){if(b===a&&(b=""),document.writeln(b+this),null!==this.sub){b+=" ";for(var c=0,d=this.sub.length;d>c;++c)this.sub[c].print(b)}},c.prototype.toPrettyString=function(b){b===a&&(b="");var c=b+this.typeName()+" @"+this.stream.pos;if(this.length>=0&&(c+="+"),c+=this.length,32&this.tag?c+=" (constructed)":3!=this.tag&&4!=this.tag||null===this.sub||(c+=" (encapsulates)"),c+="\n",null!==this.sub){b+=" ";for(var d=0,e=this.sub.length;e>d;++d)c+=this.sub[d].toPrettyString(b)}return c},c.prototype.toDOM=function(){var a=f.tag("div","node");a.asn1=this;var b=f.tag("div","head"),c=this.typeName().replace(/_/g," ");b.innerHTML=c;var d=this.content();if(null!==d){d=String(d).replace(/",c+="Length: "+this.header+"+",c+=this.length>=0?this.length:-this.length+" (undefined)",32&this.tag?c+="
(constructed)":3!=this.tag&&4!=this.tag||null===this.sub||(c+="
(encapsulates)"),null!==d&&(c+="
Value:
"+d+"","object"==typeof oids&&6==this.tag)){var h=oids[d];h&&(h.d&&(c+="
"+h.d),h.c&&(c+="
"+h.c),h.w&&(c+="
(warning!)"))}g.innerHTML=c,a.appendChild(g);var i=f.tag("div","sub");if(null!==this.sub)for(var j=0,k=this.sub.length;k>j;++j)i.appendChild(this.sub[j].toDOM());return a.appendChild(i),b.onclick=function(){a.className="node collapsed"==a.className?"node":"node collapsed"},a},c.prototype.posStart=function(){return this.stream.pos},c.prototype.posContent=function(){return this.stream.pos+this.header},c.prototype.posEnd=function(){return this.stream.pos+this.header+Math.abs(this.length)},c.prototype.fakeHover=function(a){this.node.className+=" hover",a&&(this.head.className+=" hover")},c.prototype.fakeOut=function(a){var b=/ ?hover/;this.node.className=this.node.className.replace(b,""),a&&(this.head.className=this.head.className.replace(b,""))},c.prototype.toHexDOM_sub=function(a,b,c,d,e){if(!(d>=e)){var g=f.tag("span",b);g.appendChild(f.text(c.hexDump(d,e))),a.appendChild(g)}},c.prototype.toHexDOM=function(b){var c=f.tag("span","hex");if(b===a&&(b=c),this.head.hexNode=c,this.head.onmouseover=function(){this.hexNode.className="hexCurrent"},this.head.onmouseout=function(){this.hexNode.className="hex"},c.asn1=this,c.onmouseover=function(){var a=!b.selected;a&&(b.selected=this.asn1,this.className="hexCurrent"),this.asn1.fakeHover(a)},c.onmouseout=function(){var a=b.selected==this.asn1;this.asn1.fakeOut(a),a&&(b.selected=null,this.className="hex")},this.toHexDOM_sub(c,"tag",this.stream,this.posStart(),this.posStart()+1),this.toHexDOM_sub(c,this.length>=0?"dlen":"ulen",this.stream,this.posStart()+1,this.posContent()),null===this.sub)c.appendChild(f.text(this.stream.hexDump(this.posContent(),this.posEnd())));else if(this.sub.length>0){var d=this.sub[0],e=this.sub[this.sub.length-1];this.toHexDOM_sub(c,"intro",this.stream,this.posContent(),d.posStart());for(var g=0,h=this.sub.length;h>g;++g)c.appendChild(this.sub[g].toHexDOM(b));this.toHexDOM_sub(c,"outro",this.stream,e.posEnd(),this.posEnd())}return c},c.prototype.toHexString=function(){return this.stream.hexDump(this.posStart(),this.posEnd(),!0)},c.decodeLength=function(a){var b=a.get(),c=127&b;if(c==b)return c;if(c>3)throw"Length over 24 bits not supported at position "+(a.pos-1);if(0===c)return-1;b=0;for(var d=0;c>d;++d)b=b<<8|a.get();return b},c.hasContent=function(a,d,e){if(32&a)return!0;if(3>a||a>4)return!1;var f=new b(e);3==a&&f.get();var g=f.get();if(g>>6&1)return!1;try{var h=c.decodeLength(f);return f.pos-e.pos+h==d}catch(i){return!1}},c.decode=function(a){a instanceof b||(a=new b(a,0));var d=new b(a),e=a.get(),f=c.decodeLength(a),g=a.pos-d.pos,h=null;if(c.hasContent(e,f,a)){var i=a.pos;if(3==e&&a.get(),h=[],f>=0){for(var j=i+f;a.posd;++d){var f=new b(a[d].value,0),g=c.decodeLength(f);g!=a[d].expected&&document.write("In test["+d+"] expected "+a[d].expected+" got "+g+"\n")}},window.ASN1=c}(),ASN1.prototype.getHexStringValue=function(){var a=this.toHexString(),b=2*this.header,c=2*this.length;return a.substr(b,c)},RSAKey.prototype.parseKey=function(a){try{var b=0,c=0,d=/^\s*(?:[0-9A-Fa-f][0-9A-Fa-f]\s*)+$/,e=d.test(a)?Hex.decode(a):Base64.unarmor(a),f=ASN1.decode(e);if(3===f.sub.length&&(f=f.sub[2].sub[0]),9===f.sub.length){b=f.sub[1].getHexStringValue(),this.n=parseBigInt(b,16),c=f.sub[2].getHexStringValue(),this.e=parseInt(c,16);var g=f.sub[3].getHexStringValue();this.d=parseBigInt(g,16);var h=f.sub[4].getHexStringValue();this.p=parseBigInt(h,16);var i=f.sub[5].getHexStringValue();this.q=parseBigInt(i,16);var j=f.sub[6].getHexStringValue();this.dmp1=parseBigInt(j,16);var k=f.sub[7].getHexStringValue();this.dmq1=parseBigInt(k,16);var l=f.sub[8].getHexStringValue();this.coeff=parseBigInt(l,16)}else{if(2!==f.sub.length)return!1;var m=f.sub[1],n=m.sub[0];b=n.sub[0].getHexStringValue(),this.n=parseBigInt(b,16),c=n.sub[1].getHexStringValue(),this.e=parseInt(c,16)}return!0}catch(o){return!1}},RSAKey.prototype.getPrivateBaseKey=function(){var a={array:[new KJUR.asn1.DERInteger({"int":0}),new KJUR.asn1.DERInteger({bigint:this.n}),new KJUR.asn1.DERInteger({"int":this.e}),new KJUR.asn1.DERInteger({bigint:this.d}),new KJUR.asn1.DERInteger({bigint:this.p}),new KJUR.asn1.DERInteger({bigint:this.q}),new KJUR.asn1.DERInteger({bigint:this.dmp1}),new KJUR.asn1.DERInteger({bigint:this.dmq1}),new KJUR.asn1.DERInteger({bigint:this.coeff})]},b=new KJUR.asn1.DERSequence(a);return b.getEncodedHex()},RSAKey.prototype.getPrivateBaseKeyB64=function(){return hex2b64(this.getPrivateBaseKey())},RSAKey.prototype.getPublicBaseKey=function(){var a={array:[new KJUR.asn1.DERObjectIdentifier({oid:"1.2.840.113549.1.1.1"}),new KJUR.asn1.DERNull]},b=new KJUR.asn1.DERSequence(a);a={array:[new KJUR.asn1.DERInteger({bigint:this.n}),new KJUR.asn1.DERInteger({"int":this.e})]};var c=new KJUR.asn1.DERSequence(a);a={hex:"00"+c.getEncodedHex()};var d=new KJUR.asn1.DERBitString(a);a={array:[b,d]};var e=new KJUR.asn1.DERSequence(a);return e.getEncodedHex()},RSAKey.prototype.getPublicBaseKeyB64=function(){return hex2b64(this.getPublicBaseKey())},RSAKey.prototype.wordwrap=function(a,b){if(b=b||64,!a)return a;var c="(.{1,"+b+"})( +|$\n?)|(.{1,"+b+"})";return a.match(RegExp(c,"g")).join("\n")},RSAKey.prototype.getPrivateKey=function(){var a="-----BEGIN RSA PRIVATE KEY-----\n";return a+=this.wordwrap(this.getPrivateBaseKeyB64())+"\n",a+="-----END RSA PRIVATE KEY-----"},RSAKey.prototype.getPublicKey=function(){var a="-----BEGIN PUBLIC KEY-----\n";return a+=this.wordwrap(this.getPublicBaseKeyB64())+"\n",a+="-----END PUBLIC KEY-----"},RSAKey.prototype.hasPublicKeyProperty=function(a){return a=a||{},a.hasOwnProperty("n")&&a.hasOwnProperty("e")},RSAKey.prototype.hasPrivateKeyProperty=function(a){return a=a||{},a.hasOwnProperty("n")&&a.hasOwnProperty("e")&&a.hasOwnProperty("d")&&a.hasOwnProperty("p")&&a.hasOwnProperty("q")&&a.hasOwnProperty("dmp1")&&a.hasOwnProperty("dmq1")&&a.hasOwnProperty("coeff")},RSAKey.prototype.parsePropertiesFrom=function(a){this.n=a.n,this.e=a.e,a.hasOwnProperty("d")&&(this.d=a.d,this.p=a.p,this.q=a.q,this.dmp1=a.dmp1,this.dmq1=a.dmq1,this.coeff=a.coeff)};var JSEncryptRSAKey=function(a){RSAKey.call(this),a&&("string"==typeof a?this.parseKey(a):(this.hasPrivateKeyProperty(a)||this.hasPublicKeyProperty(a))&&this.parsePropertiesFrom(a))};JSEncryptRSAKey.prototype=new RSAKey,JSEncryptRSAKey.prototype.constructor=JSEncryptRSAKey;var JSEncrypt=function(a){a=a||{},this.default_key_size=parseInt(a.default_key_size)||1024,this.default_public_exponent=a.default_public_exponent||"010001",this.log=a.log||!1,this.key=null};JSEncrypt.prototype.setKey=function(a){this.log&&this.key&&console.warn("A key was already set, overriding existing."),this.key=new JSEncryptRSAKey(a)},JSEncrypt.prototype.setPrivateKey=function(a){this.setKey(a)},JSEncrypt.prototype.setPublicKey=function(a){this.setKey(a)},JSEncrypt.prototype.decrypt=function(a){try{return this.getKey().decrypt(b64tohex(a))}catch(b){return!1}},JSEncrypt.prototype.encrypt=function(a){try{return hex2b64(this.getKey().encrypt(a))}catch(b){return!1}},JSEncrypt.prototype.getKey=function(a){if(!this.key){if(this.key=new JSEncryptRSAKey,a&&"[object Function]"==={}.toString.call(a))return void this.key.generateAsync(this.default_key_size,this.default_public_exponent,a);this.key.generate(this.default_key_size,this.default_public_exponent)}return this.key},JSEncrypt.prototype.getPrivateKey=function(){return this.getKey().getPrivateKey()},JSEncrypt.prototype.getPrivateKeyB64=function(){return this.getKey().getPrivateBaseKeyB64()},JSEncrypt.prototype.getPublicKey=function(){return this.getKey().getPublicKey()},JSEncrypt.prototype.getPublicKeyB64=function(){return this.getKey().getPublicBaseKeyB64()};exports.JSEncrypt = JSEncrypt; 5 | })(JSEncryptExports); 6 | var JSEncrypt = JSEncryptExports.JSEncrypt; 7 | -------------------------------------------------------------------------------- /test/TestScript/des/des.js: -------------------------------------------------------------------------------- 1 | /** 2 | * DES encryption/decryption 3 | * @Copyright Copyright (c) 2006 4 | * @author Guapo 5 | * @see DESCore 6 | */ 7 | 8 | /* 9 | * encrypt the string to string made up of hex 10 | * return the encrypted string 11 | * encryption 12 | */ 13 | function strEnc(data,firstKey,secondKey,thirdKey){ 14 | 15 | var leng = data.length; 16 | var encData = ""; 17 | var firstKeyBt,secondKeyBt,thirdKeyBt,firstLength,secondLength,thirdLength; 18 | if(firstKey != null && firstKey != ""){ 19 | firstKeyBt = getKeyBytes(firstKey); 20 | firstLength = firstKeyBt.length; 21 | } 22 | if(secondKey != null && secondKey != ""){ 23 | secondKeyBt = getKeyBytes(secondKey); 24 | secondLength = secondKeyBt.length; 25 | } 26 | if(thirdKey != null && thirdKey != ""){ 27 | thirdKeyBt = getKeyBytes(thirdKey); 28 | thirdLength = thirdKeyBt.length; 29 | } 30 | 31 | if(leng > 0){ 32 | if(leng < 4){ 33 | var bt = strToBt(data); 34 | var encByte ; 35 | if(firstKey != null && firstKey !="" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != ""){ 36 | var tempBt; 37 | var x,y,z; 38 | tempBt = bt; 39 | for(x = 0;x < firstLength ;x ++){ 40 | tempBt = enc(tempBt,firstKeyBt[x]); 41 | } 42 | for(y = 0;y < secondLength ;y ++){ 43 | tempBt = enc(tempBt,secondKeyBt[y]); 44 | } 45 | for(z = 0;z < thirdLength ;z ++){ 46 | tempBt = enc(tempBt,thirdKeyBt[z]); 47 | } 48 | encByte = tempBt; 49 | }else{ 50 | if(firstKey != null && firstKey !="" && secondKey != null && secondKey != ""){ 51 | var tempBt; 52 | var x,y; 53 | tempBt = bt; 54 | for(x = 0;x < firstLength ;x ++){ 55 | tempBt = enc(tempBt,firstKeyBt[x]); 56 | } 57 | for(y = 0;y < secondLength ;y ++){ 58 | tempBt = enc(tempBt,secondKeyBt[y]); 59 | } 60 | encByte = tempBt; 61 | }else{ 62 | if(firstKey != null && firstKey !=""){ 63 | var tempBt; 64 | var x = 0; 65 | tempBt = bt; 66 | for(x = 0;x < firstLength ;x ++){ 67 | tempBt = enc(tempBt,firstKeyBt[x]); 68 | } 69 | encByte = tempBt; 70 | } 71 | } 72 | } 73 | encData = bt64ToHex(encByte); 74 | }else{ 75 | var iterator = parseInt(leng/4); 76 | var remainder = leng%4; 77 | var i=0; 78 | for(i = 0;i < iterator;i++){ 79 | var tempData = data.substring(i*4+0,i*4+4); 80 | var tempByte = strToBt(tempData); 81 | var encByte ; 82 | if(firstKey != null && firstKey !="" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != ""){ 83 | var tempBt; 84 | var x,y,z; 85 | tempBt = tempByte; 86 | for(x = 0;x < firstLength ;x ++){ 87 | tempBt = enc(tempBt,firstKeyBt[x]); 88 | } 89 | for(y = 0;y < secondLength ;y ++){ 90 | tempBt = enc(tempBt,secondKeyBt[y]); 91 | } 92 | for(z = 0;z < thirdLength ;z ++){ 93 | tempBt = enc(tempBt,thirdKeyBt[z]); 94 | } 95 | encByte = tempBt; 96 | }else{ 97 | if(firstKey != null && firstKey !="" && secondKey != null && secondKey != ""){ 98 | var tempBt; 99 | var x,y; 100 | tempBt = tempByte; 101 | for(x = 0;x < firstLength ;x ++){ 102 | tempBt = enc(tempBt,firstKeyBt[x]); 103 | } 104 | for(y = 0;y < secondLength ;y ++){ 105 | tempBt = enc(tempBt,secondKeyBt[y]); 106 | } 107 | encByte = tempBt; 108 | }else{ 109 | if(firstKey != null && firstKey !=""){ 110 | var tempBt; 111 | var x; 112 | tempBt = tempByte; 113 | for(x = 0;x < firstLength ;x ++){ 114 | tempBt = enc(tempBt,firstKeyBt[x]); 115 | } 116 | encByte = tempBt; 117 | } 118 | } 119 | } 120 | encData += bt64ToHex(encByte); 121 | } 122 | if(remainder > 0){ 123 | var remainderData = data.substring(iterator*4+0,leng); 124 | var tempByte = strToBt(remainderData); 125 | var encByte ; 126 | if(firstKey != null && firstKey !="" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != ""){ 127 | var tempBt; 128 | var x,y,z; 129 | tempBt = tempByte; 130 | for(x = 0;x < firstLength ;x ++){ 131 | tempBt = enc(tempBt,firstKeyBt[x]); 132 | } 133 | for(y = 0;y < secondLength ;y ++){ 134 | tempBt = enc(tempBt,secondKeyBt[y]); 135 | } 136 | for(z = 0;z < thirdLength ;z ++){ 137 | tempBt = enc(tempBt,thirdKeyBt[z]); 138 | } 139 | encByte = tempBt; 140 | }else{ 141 | if(firstKey != null && firstKey !="" && secondKey != null && secondKey != ""){ 142 | var tempBt; 143 | var x,y; 144 | tempBt = tempByte; 145 | for(x = 0;x < firstLength ;x ++){ 146 | tempBt = enc(tempBt,firstKeyBt[x]); 147 | } 148 | for(y = 0;y < secondLength ;y ++){ 149 | tempBt = enc(tempBt,secondKeyBt[y]); 150 | } 151 | encByte = tempBt; 152 | }else{ 153 | if(firstKey != null && firstKey !=""){ 154 | var tempBt; 155 | var x; 156 | tempBt = tempByte; 157 | for(x = 0;x < firstLength ;x ++){ 158 | tempBt = enc(tempBt,firstKeyBt[x]); 159 | } 160 | encByte = tempBt; 161 | } 162 | } 163 | } 164 | encData += bt64ToHex(encByte); 165 | } 166 | } 167 | } 168 | return encData; 169 | } 170 | 171 | /* 172 | * decrypt the encrypted string to the original string 173 | * 174 | * return the original string 175 | */ 176 | function strDec(data,firstKey,secondKey,thirdKey){ 177 | var leng = data.length; 178 | var decStr = ""; 179 | var firstKeyBt,secondKeyBt,thirdKeyBt,firstLength,secondLength,thirdLength; 180 | if(firstKey != null && firstKey != ""){ 181 | firstKeyBt = getKeyBytes(firstKey); 182 | firstLength = firstKeyBt.length; 183 | } 184 | if(secondKey != null && secondKey != ""){ 185 | secondKeyBt = getKeyBytes(secondKey); 186 | secondLength = secondKeyBt.length; 187 | } 188 | if(thirdKey != null && thirdKey != ""){ 189 | thirdKeyBt = getKeyBytes(thirdKey); 190 | thirdLength = thirdKeyBt.length; 191 | } 192 | 193 | var iterator = parseInt(leng/16); 194 | var i=0; 195 | for(i = 0;i < iterator;i++){ 196 | var tempData = data.substring(i*16+0,i*16+16); 197 | var strByte = hexToBt64(tempData); 198 | var intByte = new Array(64); 199 | var j = 0; 200 | for(j = 0;j < 64; j++){ 201 | intByte[j] = parseInt(strByte.substring(j,j+1)); 202 | } 203 | var decByte; 204 | if(firstKey != null && firstKey !="" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != ""){ 205 | var tempBt; 206 | var x,y,z; 207 | tempBt = intByte; 208 | for(x = thirdLength - 1;x >= 0;x --){ 209 | tempBt = dec(tempBt,thirdKeyBt[x]); 210 | } 211 | for(y = secondLength - 1;y >= 0;y --){ 212 | tempBt = dec(tempBt,secondKeyBt[y]); 213 | } 214 | for(z = firstLength - 1;z >= 0 ;z --){ 215 | tempBt = dec(tempBt,firstKeyBt[z]); 216 | } 217 | decByte = tempBt; 218 | }else{ 219 | if(firstKey != null && firstKey !="" && secondKey != null && secondKey != ""){ 220 | var tempBt; 221 | var x,y,z; 222 | tempBt = intByte; 223 | for(x = secondLength - 1;x >= 0 ;x --){ 224 | tempBt = dec(tempBt,secondKeyBt[x]); 225 | } 226 | for(y = firstLength - 1;y >= 0 ;y --){ 227 | tempBt = dec(tempBt,firstKeyBt[y]); 228 | } 229 | decByte = tempBt; 230 | }else{ 231 | if(firstKey != null && firstKey !=""){ 232 | var tempBt; 233 | var x,y,z; 234 | tempBt = intByte; 235 | for(x = firstLength - 1;x >= 0 ;x --){ 236 | tempBt = dec(tempBt,firstKeyBt[x]); 237 | } 238 | decByte = tempBt; 239 | } 240 | } 241 | } 242 | decStr += byteToString(decByte); 243 | } 244 | return decStr; 245 | } 246 | /* 247 | * chang the string into the bit array 248 | * 249 | * return bit array(it's length % 64 = 0) 250 | */ 251 | function getKeyBytes(key){ 252 | var keyBytes = new Array(); 253 | var leng = key.length; 254 | var iterator = parseInt(leng/4); 255 | var remainder = leng%4; 256 | var i = 0; 257 | for(i = 0;i < iterator; i ++){ 258 | keyBytes[i] = strToBt(key.substring(i*4+0,i*4+4)); 259 | } 260 | if(remainder > 0){ 261 | keyBytes[i] = strToBt(key.substring(i*4+0,leng)); 262 | } 263 | return keyBytes; 264 | } 265 | 266 | /* 267 | * chang the string(it's length <= 4) into the bit array 268 | * 269 | * return bit array(it's length = 64) 270 | */ 271 | function strToBt(str){ 272 | var leng = str.length; 273 | var bt = new Array(64); 274 | if(leng < 4){ 275 | var i=0,j=0,p=0,q=0; 276 | for(i = 0;ij;m--){ 281 | pow *= 2; 282 | } 283 | bt[16*i+j]=parseInt(k/pow)%2; 284 | } 285 | } 286 | for(p = leng;p<4;p++){ 287 | var k = 0; 288 | for(q=0;q<16;q++){ 289 | var pow=1,m=0; 290 | for(m=15;m>q;m--){ 291 | pow *= 2; 292 | } 293 | bt[16*p+q]=parseInt(k/pow)%2; 294 | } 295 | } 296 | }else{ 297 | for(i = 0;i<4;i++){ 298 | var k = str.charCodeAt(i); 299 | for(j=0;j<16;j++){ 300 | var pow=1; 301 | for(m=15;m>j;m--){ 302 | pow *= 2; 303 | } 304 | bt[16*i+j]=parseInt(k/pow)%2; 305 | } 306 | } 307 | } 308 | return bt; 309 | } 310 | 311 | /* 312 | * chang the bit(it's length = 4) into the hex 313 | * 314 | * return hex 315 | */ 316 | function bt4ToHex(binary) { 317 | var hex; 318 | switch (binary) { 319 | case "0000" : hex = "0"; break; 320 | case "0001" : hex = "1"; break; 321 | case "0010" : hex = "2"; break; 322 | case "0011" : hex = "3"; break; 323 | case "0100" : hex = "4"; break; 324 | case "0101" : hex = "5"; break; 325 | case "0110" : hex = "6"; break; 326 | case "0111" : hex = "7"; break; 327 | case "1000" : hex = "8"; break; 328 | case "1001" : hex = "9"; break; 329 | case "1010" : hex = "A"; break; 330 | case "1011" : hex = "B"; break; 331 | case "1100" : hex = "C"; break; 332 | case "1101" : hex = "D"; break; 333 | case "1110" : hex = "E"; break; 334 | case "1111" : hex = "F"; break; 335 | } 336 | return hex; 337 | } 338 | 339 | /* 340 | * chang the hex into the bit(it's length = 4) 341 | * 342 | * return the bit(it's length = 4) 343 | */ 344 | function hexToBt4(hex) { 345 | var binary; 346 | switch (hex) { 347 | case "0" : binary = "0000"; break; 348 | case "1" : binary = "0001"; break; 349 | case "2" : binary = "0010"; break; 350 | case "3" : binary = "0011"; break; 351 | case "4" : binary = "0100"; break; 352 | case "5" : binary = "0101"; break; 353 | case "6" : binary = "0110"; break; 354 | case "7" : binary = "0111"; break; 355 | case "8" : binary = "1000"; break; 356 | case "9" : binary = "1001"; break; 357 | case "A" : binary = "1010"; break; 358 | case "B" : binary = "1011"; break; 359 | case "C" : binary = "1100"; break; 360 | case "D" : binary = "1101"; break; 361 | case "E" : binary = "1110"; break; 362 | case "F" : binary = "1111"; break; 363 | } 364 | return binary; 365 | } 366 | 367 | /* 368 | * chang the bit(it's length = 64) into the string 369 | * 370 | * return string 371 | */ 372 | function byteToString(byteData){ 373 | var str=""; 374 | for(i = 0;i<4;i++){ 375 | var count=0; 376 | for(j=0;j<16;j++){ 377 | var pow=1; 378 | for(m=15;m>j;m--){ 379 | pow*=2; 380 | } 381 | count+=byteData[16*i+j]*pow; 382 | } 383 | if(count != 0){ 384 | str+=String.fromCharCode(count); 385 | } 386 | } 387 | return str; 388 | } 389 | 390 | function bt64ToHex(byteData){ 391 | var hex = ""; 392 | for(i = 0;i<16;i++){ 393 | var bt = ""; 394 | for(j=0;j<4;j++){ 395 | bt += byteData[i*4+j]; 396 | } 397 | hex+=bt4ToHex(bt); 398 | } 399 | return hex; 400 | } 401 | 402 | function hexToBt64(hex){ 403 | var binary = ""; 404 | for(i = 0;i<16;i++){ 405 | binary+=hexToBt4(hex.substring(i,i+1)); 406 | } 407 | return binary; 408 | } 409 | 410 | /* 411 | * the 64 bit des core arithmetic 412 | */ 413 | 414 | function enc(dataByte,keyByte){ 415 | var keys = generateKeys(keyByte); 416 | var ipByte = initPermute(dataByte); 417 | var ipLeft = new Array(32); 418 | var ipRight = new Array(32); 419 | var tempLeft = new Array(32); 420 | var i = 0,j = 0,k = 0,m = 0, n = 0; 421 | for(k = 0;k < 32;k ++){ 422 | ipLeft[k] = ipByte[k]; 423 | ipRight[k] = ipByte[32+k]; 424 | } 425 | for(i = 0;i < 16;i ++){ 426 | for(j = 0;j < 32;j ++){ 427 | tempLeft[j] = ipLeft[j]; 428 | ipLeft[j] = ipRight[j]; 429 | } 430 | var key = new Array(48); 431 | for(m = 0;m < 48;m ++){ 432 | key[m] = keys[i][m]; 433 | } 434 | var tempRight = xor(pPermute(sBoxPermute(xor(expandPermute(ipRight),key))), tempLeft); 435 | for(n = 0;n < 32;n ++){ 436 | ipRight[n] = tempRight[n]; 437 | } 438 | 439 | } 440 | 441 | 442 | var finalData =new Array(64); 443 | for(i = 0;i < 32;i ++){ 444 | finalData[i] = ipRight[i]; 445 | finalData[32+i] = ipLeft[i]; 446 | } 447 | return finallyPermute(finalData); 448 | } 449 | 450 | function dec(dataByte,keyByte){ 451 | var keys = generateKeys(keyByte); 452 | var ipByte = initPermute(dataByte); 453 | var ipLeft = new Array(32); 454 | var ipRight = new Array(32); 455 | var tempLeft = new Array(32); 456 | var i = 0,j = 0,k = 0,m = 0, n = 0; 457 | for(k = 0;k < 32;k ++){ 458 | ipLeft[k] = ipByte[k]; 459 | ipRight[k] = ipByte[32+k]; 460 | } 461 | for(i = 15;i >= 0;i --){ 462 | for(j = 0;j < 32;j ++){ 463 | tempLeft[j] = ipLeft[j]; 464 | ipLeft[j] = ipRight[j]; 465 | } 466 | var key = new Array(48); 467 | for(m = 0;m < 48;m ++){ 468 | key[m] = keys[i][m]; 469 | } 470 | 471 | var tempRight = xor(pPermute(sBoxPermute(xor(expandPermute(ipRight),key))), tempLeft); 472 | for(n = 0;n < 32;n ++){ 473 | ipRight[n] = tempRight[n]; 474 | } 475 | } 476 | 477 | 478 | var finalData =new Array(64); 479 | for(i = 0;i < 32;i ++){ 480 | finalData[i] = ipRight[i]; 481 | finalData[32+i] = ipLeft[i]; 482 | } 483 | return finallyPermute(finalData); 484 | } 485 | 486 | function initPermute(originalData){ 487 | var ipByte = new Array(64); 488 | for (i = 0, m = 1, n = 0; i < 4; i++, m += 2, n += 2) { 489 | for (j = 7, k = 0; j >= 0; j--, k++) { 490 | ipByte[i * 8 + k] = originalData[j * 8 + m]; 491 | ipByte[i * 8 + k + 32] = originalData[j * 8 + n]; 492 | } 493 | } 494 | return ipByte; 495 | } 496 | 497 | function expandPermute(rightData){ 498 | var epByte = new Array(48); 499 | for (i = 0; i < 8; i++) { 500 | if (i == 0) { 501 | epByte[i * 6 + 0] = rightData[31]; 502 | } else { 503 | epByte[i * 6 + 0] = rightData[i * 4 - 1]; 504 | } 505 | epByte[i * 6 + 1] = rightData[i * 4 + 0]; 506 | epByte[i * 6 + 2] = rightData[i * 4 + 1]; 507 | epByte[i * 6 + 3] = rightData[i * 4 + 2]; 508 | epByte[i * 6 + 4] = rightData[i * 4 + 3]; 509 | if (i == 7) { 510 | epByte[i * 6 + 5] = rightData[0]; 511 | } else { 512 | epByte[i * 6 + 5] = rightData[i * 4 + 4]; 513 | } 514 | } 515 | return epByte; 516 | } 517 | 518 | function xor(byteOne,byteTwo){ 519 | var xorByte = new Array(byteOne.length); 520 | for(i = 0;i < byteOne.length; i ++){ 521 | xorByte[i] = byteOne[i] ^ byteTwo[i]; 522 | } 523 | return xorByte; 524 | } 525 | 526 | function sBoxPermute(expandByte){ 527 | 528 | var sBoxByte = new Array(32); 529 | var binary = ""; 530 | var s1 = [ 531 | [14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7], 532 | [0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8], 533 | [4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0], 534 | [15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13 ]]; 535 | 536 | /* Table - s2 */ 537 | var s2 = [ 538 | [15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10], 539 | [3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5], 540 | [0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15], 541 | [13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9 ]]; 542 | 543 | /* Table - s3 */ 544 | var s3= [ 545 | [10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8], 546 | [13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1], 547 | [13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7], 548 | [1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12 ]]; 549 | /* Table - s4 */ 550 | var s4 = [ 551 | [7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15], 552 | [13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9], 553 | [10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4], 554 | [3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14 ]]; 555 | 556 | /* Table - s5 */ 557 | var s5 = [ 558 | [2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9], 559 | [14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6], 560 | [4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14], 561 | [11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3 ]]; 562 | 563 | /* Table - s6 */ 564 | var s6 = [ 565 | [12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11], 566 | [10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8], 567 | [9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6], 568 | [4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13 ]]; 569 | 570 | /* Table - s7 */ 571 | var s7 = [ 572 | [4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1], 573 | [13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6], 574 | [1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2], 575 | [6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12]]; 576 | 577 | /* Table - s8 */ 578 | var s8 = [ 579 | [13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7], 580 | [1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2], 581 | [7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8], 582 | [2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11]]; 583 | 584 | for(m=0;m<8;m++){ 585 | var i=0,j=0; 586 | i = expandByte[m*6+0]*2+expandByte[m*6+5]; 587 | j = expandByte[m * 6 + 1] * 2 * 2 * 2 588 | + expandByte[m * 6 + 2] * 2* 2 589 | + expandByte[m * 6 + 3] * 2 590 | + expandByte[m * 6 + 4]; 591 | switch (m) { 592 | case 0 : 593 | binary = getBoxBinary(s1[i][j]); 594 | break; 595 | case 1 : 596 | binary = getBoxBinary(s2[i][j]); 597 | break; 598 | case 2 : 599 | binary = getBoxBinary(s3[i][j]); 600 | break; 601 | case 3 : 602 | binary = getBoxBinary(s4[i][j]); 603 | break; 604 | case 4 : 605 | binary = getBoxBinary(s5[i][j]); 606 | break; 607 | case 5 : 608 | binary = getBoxBinary(s6[i][j]); 609 | break; 610 | case 6 : 611 | binary = getBoxBinary(s7[i][j]); 612 | break; 613 | case 7 : 614 | binary = getBoxBinary(s8[i][j]); 615 | break; 616 | } 617 | sBoxByte[m*4+0] = parseInt(binary.substring(0,1)); 618 | sBoxByte[m*4+1] = parseInt(binary.substring(1,2)); 619 | sBoxByte[m*4+2] = parseInt(binary.substring(2,3)); 620 | sBoxByte[m*4+3] = parseInt(binary.substring(3,4)); 621 | } 622 | return sBoxByte; 623 | } 624 | 625 | function pPermute(sBoxByte){ 626 | var pBoxPermute = new Array(32); 627 | pBoxPermute[ 0] = sBoxByte[15]; 628 | pBoxPermute[ 1] = sBoxByte[ 6]; 629 | pBoxPermute[ 2] = sBoxByte[19]; 630 | pBoxPermute[ 3] = sBoxByte[20]; 631 | pBoxPermute[ 4] = sBoxByte[28]; 632 | pBoxPermute[ 5] = sBoxByte[11]; 633 | pBoxPermute[ 6] = sBoxByte[27]; 634 | pBoxPermute[ 7] = sBoxByte[16]; 635 | pBoxPermute[ 8] = sBoxByte[ 0]; 636 | pBoxPermute[ 9] = sBoxByte[14]; 637 | pBoxPermute[10] = sBoxByte[22]; 638 | pBoxPermute[11] = sBoxByte[25]; 639 | pBoxPermute[12] = sBoxByte[ 4]; 640 | pBoxPermute[13] = sBoxByte[17]; 641 | pBoxPermute[14] = sBoxByte[30]; 642 | pBoxPermute[15] = sBoxByte[ 9]; 643 | pBoxPermute[16] = sBoxByte[ 1]; 644 | pBoxPermute[17] = sBoxByte[ 7]; 645 | pBoxPermute[18] = sBoxByte[23]; 646 | pBoxPermute[19] = sBoxByte[13]; 647 | pBoxPermute[20] = sBoxByte[31]; 648 | pBoxPermute[21] = sBoxByte[26]; 649 | pBoxPermute[22] = sBoxByte[ 2]; 650 | pBoxPermute[23] = sBoxByte[ 8]; 651 | pBoxPermute[24] = sBoxByte[18]; 652 | pBoxPermute[25] = sBoxByte[12]; 653 | pBoxPermute[26] = sBoxByte[29]; 654 | pBoxPermute[27] = sBoxByte[ 5]; 655 | pBoxPermute[28] = sBoxByte[21]; 656 | pBoxPermute[29] = sBoxByte[10]; 657 | pBoxPermute[30] = sBoxByte[ 3]; 658 | pBoxPermute[31] = sBoxByte[24]; 659 | return pBoxPermute; 660 | } 661 | 662 | function finallyPermute(endByte){ 663 | var fpByte = new Array(64); 664 | fpByte[ 0] = endByte[39]; 665 | fpByte[ 1] = endByte[ 7]; 666 | fpByte[ 2] = endByte[47]; 667 | fpByte[ 3] = endByte[15]; 668 | fpByte[ 4] = endByte[55]; 669 | fpByte[ 5] = endByte[23]; 670 | fpByte[ 6] = endByte[63]; 671 | fpByte[ 7] = endByte[31]; 672 | fpByte[ 8] = endByte[38]; 673 | fpByte[ 9] = endByte[ 6]; 674 | fpByte[10] = endByte[46]; 675 | fpByte[11] = endByte[14]; 676 | fpByte[12] = endByte[54]; 677 | fpByte[13] = endByte[22]; 678 | fpByte[14] = endByte[62]; 679 | fpByte[15] = endByte[30]; 680 | fpByte[16] = endByte[37]; 681 | fpByte[17] = endByte[ 5]; 682 | fpByte[18] = endByte[45]; 683 | fpByte[19] = endByte[13]; 684 | fpByte[20] = endByte[53]; 685 | fpByte[21] = endByte[21]; 686 | fpByte[22] = endByte[61]; 687 | fpByte[23] = endByte[29]; 688 | fpByte[24] = endByte[36]; 689 | fpByte[25] = endByte[ 4]; 690 | fpByte[26] = endByte[44]; 691 | fpByte[27] = endByte[12]; 692 | fpByte[28] = endByte[52]; 693 | fpByte[29] = endByte[20]; 694 | fpByte[30] = endByte[60]; 695 | fpByte[31] = endByte[28]; 696 | fpByte[32] = endByte[35]; 697 | fpByte[33] = endByte[ 3]; 698 | fpByte[34] = endByte[43]; 699 | fpByte[35] = endByte[11]; 700 | fpByte[36] = endByte[51]; 701 | fpByte[37] = endByte[19]; 702 | fpByte[38] = endByte[59]; 703 | fpByte[39] = endByte[27]; 704 | fpByte[40] = endByte[34]; 705 | fpByte[41] = endByte[ 2]; 706 | fpByte[42] = endByte[42]; 707 | fpByte[43] = endByte[10]; 708 | fpByte[44] = endByte[50]; 709 | fpByte[45] = endByte[18]; 710 | fpByte[46] = endByte[58]; 711 | fpByte[47] = endByte[26]; 712 | fpByte[48] = endByte[33]; 713 | fpByte[49] = endByte[ 1]; 714 | fpByte[50] = endByte[41]; 715 | fpByte[51] = endByte[ 9]; 716 | fpByte[52] = endByte[49]; 717 | fpByte[53] = endByte[17]; 718 | fpByte[54] = endByte[57]; 719 | fpByte[55] = endByte[25]; 720 | fpByte[56] = endByte[32]; 721 | fpByte[57] = endByte[ 0]; 722 | fpByte[58] = endByte[40]; 723 | fpByte[59] = endByte[ 8]; 724 | fpByte[60] = endByte[48]; 725 | fpByte[61] = endByte[16]; 726 | fpByte[62] = endByte[56]; 727 | fpByte[63] = endByte[24]; 728 | return fpByte; 729 | } 730 | 731 | function getBoxBinary(i) { 732 | var binary = ""; 733 | switch (i) { 734 | case 0 :binary = "0000";break; 735 | case 1 :binary = "0001";break; 736 | case 2 :binary = "0010";break; 737 | case 3 :binary = "0011";break; 738 | case 4 :binary = "0100";break; 739 | case 5 :binary = "0101";break; 740 | case 6 :binary = "0110";break; 741 | case 7 :binary = "0111";break; 742 | case 8 :binary = "1000";break; 743 | case 9 :binary = "1001";break; 744 | case 10 :binary = "1010";break; 745 | case 11 :binary = "1011";break; 746 | case 12 :binary = "1100";break; 747 | case 13 :binary = "1101";break; 748 | case 14 :binary = "1110";break; 749 | case 15 :binary = "1111";break; 750 | } 751 | return binary; 752 | } 753 | /* 754 | * generate 16 keys for xor 755 | * 756 | */ 757 | function generateKeys(keyByte){ 758 | var key = new Array(56); 759 | var keys = new Array(); 760 | 761 | keys[ 0] = new Array(); 762 | keys[ 1] = new Array(); 763 | keys[ 2] = new Array(); 764 | keys[ 3] = new Array(); 765 | keys[ 4] = new Array(); 766 | keys[ 5] = new Array(); 767 | keys[ 6] = new Array(); 768 | keys[ 7] = new Array(); 769 | keys[ 8] = new Array(); 770 | keys[ 9] = new Array(); 771 | keys[10] = new Array(); 772 | keys[11] = new Array(); 773 | keys[12] = new Array(); 774 | keys[13] = new Array(); 775 | keys[14] = new Array(); 776 | keys[15] = new Array(); 777 | var loop = [1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1]; 778 | 779 | for(i=0;i<7;i++){ 780 | for(j=0,k=7;j<8;j++,k--){ 781 | key[i*8+j]=keyByte[8*k+i]; 782 | } 783 | } 784 | 785 | var i = 0; 786 | for(i = 0;i < 16;i ++){ 787 | var tempLeft=0; 788 | var tempRight=0; 789 | for(j = 0; j < loop[i];j ++){ 790 | tempLeft = key[0]; 791 | tempRight = key[28]; 792 | for(k = 0;k < 27 ;k ++){ 793 | key[k] = key[k+1]; 794 | key[28+k] = key[29+k]; 795 | } 796 | key[27]=tempLeft; 797 | key[55]=tempRight; 798 | } 799 | var tempKey = new Array(48); 800 | tempKey[ 0] = key[13]; 801 | tempKey[ 1] = key[16]; 802 | tempKey[ 2] = key[10]; 803 | tempKey[ 3] = key[23]; 804 | tempKey[ 4] = key[ 0]; 805 | tempKey[ 5] = key[ 4]; 806 | tempKey[ 6] = key[ 2]; 807 | tempKey[ 7] = key[27]; 808 | tempKey[ 8] = key[14]; 809 | tempKey[ 9] = key[ 5]; 810 | tempKey[10] = key[20]; 811 | tempKey[11] = key[ 9]; 812 | tempKey[12] = key[22]; 813 | tempKey[13] = key[18]; 814 | tempKey[14] = key[11]; 815 | tempKey[15] = key[ 3]; 816 | tempKey[16] = key[25]; 817 | tempKey[17] = key[ 7]; 818 | tempKey[18] = key[15]; 819 | tempKey[19] = key[ 6]; 820 | tempKey[20] = key[26]; 821 | tempKey[21] = key[19]; 822 | tempKey[22] = key[12]; 823 | tempKey[23] = key[ 1]; 824 | tempKey[24] = key[40]; 825 | tempKey[25] = key[51]; 826 | tempKey[26] = key[30]; 827 | tempKey[27] = key[36]; 828 | tempKey[28] = key[46]; 829 | tempKey[29] = key[54]; 830 | tempKey[30] = key[29]; 831 | tempKey[31] = key[39]; 832 | tempKey[32] = key[50]; 833 | tempKey[33] = key[44]; 834 | tempKey[34] = key[32]; 835 | tempKey[35] = key[47]; 836 | tempKey[36] = key[43]; 837 | tempKey[37] = key[48]; 838 | tempKey[38] = key[38]; 839 | tempKey[39] = key[55]; 840 | tempKey[40] = key[33]; 841 | tempKey[41] = key[52]; 842 | tempKey[42] = key[45]; 843 | tempKey[43] = key[41]; 844 | tempKey[44] = key[49]; 845 | tempKey[45] = key[35]; 846 | tempKey[46] = key[28]; 847 | tempKey[47] = key[31]; 848 | switch(i){ 849 | case 0: for(m=0;m < 48 ;m++){ keys[ 0][m] = tempKey[m]; } break; 850 | case 1: for(m=0;m < 48 ;m++){ keys[ 1][m] = tempKey[m]; } break; 851 | case 2: for(m=0;m < 48 ;m++){ keys[ 2][m] = tempKey[m]; } break; 852 | case 3: for(m=0;m < 48 ;m++){ keys[ 3][m] = tempKey[m]; } break; 853 | case 4: for(m=0;m < 48 ;m++){ keys[ 4][m] = tempKey[m]; } break; 854 | case 5: for(m=0;m < 48 ;m++){ keys[ 5][m] = tempKey[m]; } break; 855 | case 6: for(m=0;m < 48 ;m++){ keys[ 6][m] = tempKey[m]; } break; 856 | case 7: for(m=0;m < 48 ;m++){ keys[ 7][m] = tempKey[m]; } break; 857 | case 8: for(m=0;m < 48 ;m++){ keys[ 8][m] = tempKey[m]; } break; 858 | case 9: for(m=0;m < 48 ;m++){ keys[ 9][m] = tempKey[m]; } break; 859 | case 10: for(m=0;m < 48 ;m++){ keys[10][m] = tempKey[m]; } break; 860 | case 11: for(m=0;m < 48 ;m++){ keys[11][m] = tempKey[m]; } break; 861 | case 12: for(m=0;m < 48 ;m++){ keys[12][m] = tempKey[m]; } break; 862 | case 13: for(m=0;m < 48 ;m++){ keys[13][m] = tempKey[m]; } break; 863 | case 14: for(m=0;m < 48 ;m++){ keys[14][m] = tempKey[m]; } break; 864 | case 15: for(m=0;m < 48 ;m++){ keys[15][m] = tempKey[m]; } break; 865 | } 866 | } 867 | return keys; 868 | } 869 | //end------------------------------------------------------------------------------------------------------------- 870 | /* 871 | function test() { 872 | 873 | var msg = "abcdefgh"; 874 | var bt = strToBt(msg); 875 | 876 | var key = "12345678"; 877 | var keyB = strToBt(key); 878 | 879 | var encByte = enc(bt,keyB); 880 | 881 | var enchex = bt64ToHex(encByte); 882 | endata.value=enchex; 883 | 884 | var encStr = hexToBt64(enchex); 885 | alert("encStr="+encStr); 886 | var eByte = new Array(); 887 | for(m=0;m> 5] |= 0x80 << ((len) % 32); 44 | x[(((len + 64) >>> 9) << 4) + 14] = len; 45 | 46 | var a = 1732584193; 47 | var b = -271733879; 48 | var c = -1732584194; 49 | var d = 271733878; 50 | 51 | for(var i = 0; i < x.length; i += 16) 52 | { 53 | var olda = a; 54 | var oldb = b; 55 | var oldc = c; 56 | var oldd = d; 57 | 58 | a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936); 59 | d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586); 60 | c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819); 61 | b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330); 62 | a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897); 63 | d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426); 64 | c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341); 65 | b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983); 66 | a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416); 67 | d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417); 68 | c = md5_ff(c, d, a, b, x[i+10], 17, -42063); 69 | b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162); 70 | a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682); 71 | d = md5_ff(d, a, b, c, x[i+13], 12, -40341101); 72 | c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290); 73 | b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329); 74 | 75 | a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510); 76 | d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632); 77 | c = md5_gg(c, d, a, b, x[i+11], 14, 643717713); 78 | b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302); 79 | a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691); 80 | d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083); 81 | c = md5_gg(c, d, a, b, x[i+15], 14, -660478335); 82 | b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848); 83 | a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438); 84 | d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690); 85 | c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961); 86 | b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501); 87 | a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467); 88 | d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784); 89 | c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473); 90 | b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734); 91 | 92 | a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558); 93 | d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463); 94 | c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562); 95 | b = md5_hh(b, c, d, a, x[i+14], 23, -35309556); 96 | a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060); 97 | d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353); 98 | c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632); 99 | b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640); 100 | a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174); 101 | d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222); 102 | c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979); 103 | b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189); 104 | a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487); 105 | d = md5_hh(d, a, b, c, x[i+12], 11, -421815835); 106 | c = md5_hh(c, d, a, b, x[i+15], 16, 530742520); 107 | b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651); 108 | 109 | a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844); 110 | d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415); 111 | c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905); 112 | b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055); 113 | a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571); 114 | d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606); 115 | c = md5_ii(c, d, a, b, x[i+10], 15, -1051523); 116 | b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799); 117 | a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359); 118 | d = md5_ii(d, a, b, c, x[i+15], 10, -30611744); 119 | c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380); 120 | b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649); 121 | a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070); 122 | d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379); 123 | c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259); 124 | b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551); 125 | 126 | a = safe_add(a, olda); 127 | b = safe_add(b, oldb); 128 | c = safe_add(c, oldc); 129 | d = safe_add(d, oldd); 130 | } 131 | return Array(a, b, c, d); 132 | 133 | } 134 | 135 | /* 136 | * These functions implement the four basic operations the algorithm uses. 137 | */ 138 | function md5_cmn(q, a, b, x, s, t) 139 | { 140 | return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b); 141 | } 142 | function md5_ff(a, b, c, d, x, s, t) 143 | { 144 | return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t); 145 | } 146 | function md5_gg(a, b, c, d, x, s, t) 147 | { 148 | return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t); 149 | } 150 | function md5_hh(a, b, c, d, x, s, t) 151 | { 152 | return md5_cmn(b ^ c ^ d, a, b, x, s, t); 153 | } 154 | function md5_ii(a, b, c, d, x, s, t) 155 | { 156 | return md5_cmn(c ^ (b | (~d)), a, b, x, s, t); 157 | } 158 | 159 | /* 160 | * Calculate the HMAC-MD5, of a key and some data 161 | */ 162 | function core_hmac_md5(key, data) 163 | { 164 | var bkey = str2binl(key); 165 | if(bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz); 166 | 167 | var ipad = Array(16), opad = Array(16); 168 | for(var i = 0; i < 16; i++) 169 | { 170 | ipad[i] = bkey[i] ^ 0x36363636; 171 | opad[i] = bkey[i] ^ 0x5C5C5C5C; 172 | } 173 | 174 | var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz); 175 | return core_md5(opad.concat(hash), 512 + 128); 176 | } 177 | 178 | /* 179 | * Add integers, wrapping at 2^32. This uses 16-bit operations internally 180 | * to work around bugs in some JS interpreters. 181 | */ 182 | function safe_add(x, y) 183 | { 184 | var lsw = (x & 0xFFFF) + (y & 0xFFFF); 185 | var msw = (x >> 16) + (y >> 16) + (lsw >> 16); 186 | return (msw << 16) | (lsw & 0xFFFF); 187 | } 188 | 189 | /* 190 | * Bitwise rotate a 32-bit number to the left. 191 | */ 192 | function bit_rol(num, cnt) 193 | { 194 | return (num << cnt) | (num >>> (32 - cnt)); 195 | } 196 | 197 | /* 198 | * Convert a string to an array of little-endian words 199 | * If chrsz is ASCII, characters >255 have their hi-byte silently ignored. 200 | */ 201 | function str2binl(str) 202 | { 203 | var bin = Array(); 204 | var mask = (1 << chrsz) - 1; 205 | for(var i = 0; i < str.length * chrsz; i += chrsz) 206 | bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (i%32); 207 | return bin; 208 | } 209 | 210 | /* 211 | * Convert an array of little-endian words to a string 212 | */ 213 | function binl2str(bin) 214 | { 215 | var str = ""; 216 | var mask = (1 << chrsz) - 1; 217 | for(var i = 0; i < bin.length * 32; i += chrsz) 218 | str += String.fromCharCode((bin[i>>5] >>> (i % 32)) & mask); 219 | return str; 220 | } 221 | 222 | /* 223 | * Convert an array of little-endian words to a hex string. 224 | */ 225 | function binl2hex(binarray) 226 | { 227 | var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef"; 228 | var str = ""; 229 | for(var i = 0; i < binarray.length * 4; i++) 230 | { 231 | str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) + 232 | hex_tab.charAt((binarray[i>>2] >> ((i%4)*8 )) & 0xF); 233 | } 234 | return str; 235 | } 236 | 237 | /* 238 | * Convert an array of little-endian words to a base-64 string 239 | */ 240 | function binl2b64(binarray) 241 | { 242 | var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 243 | var str = ""; 244 | for(var i = 0; i < binarray.length * 4; i += 3) 245 | { 246 | var triplet = (((binarray[i >> 2] >> 8 * ( i %4)) & 0xFF) << 16) 247 | | (((binarray[i+1 >> 2] >> 8 * ((i+1)%4)) & 0xFF) << 8 ) 248 | | ((binarray[i+2 >> 2] >> 8 * ((i+2)%4)) & 0xFF); 249 | for(var j = 0; j < 4; j++) 250 | { 251 | if(i * 8 + j * 6 > binarray.length * 32) str += b64pad; 252 | else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F); 253 | } 254 | } 255 | return str; 256 | } 257 | -------------------------------------------------------------------------------- /test/TestScript/sha1/jsEncrypter_sha1.js: -------------------------------------------------------------------------------- 1 | var webserver = require('webserver'); 2 | server = webserver.create(); 3 | 4 | var host = '127.0.0.1'; 5 | var port = '1664'; 6 | 7 | // 加载实现加密算法的js脚本 8 | var wasSuccessful = phantom.injectJs('sha1.js');/*引入实现加密的js文件*/ 9 | 10 | // 处理函数 11 | function js_encrypt(payload){ 12 | var newpayload; 13 | /**********在这里编写调用加密函数进行加密的代码************/ 14 | newpayload = hex_sha1(payload); 15 | /**********************************************************/ 16 | return newpayload; 17 | } 18 | 19 | if(wasSuccessful){ 20 | console.log("[*] load js successful"); 21 | console.log("[!] ^_^"); 22 | console.log("[*] jsEncrypterJS start!"); 23 | console.log("[+] address: http://"+host+":"+port); 24 | }else{ 25 | console.log('[*] load js fail!'); 26 | } 27 | 28 | var service = server.listen(host+':'+port,function(request, response){ 29 | try{ 30 | if(request.method == 'POST'){ 31 | var payload = request.post['payload']; 32 | var encrypt_payload = js_encrypt(payload); 33 | console.log('[+] ' + payload + ':' + encrypt_payload); 34 | response.statusCode = 200; 35 | response.write(encrypt_payload.toString()); 36 | response.close(); 37 | }else{ 38 | response.statusCode = 200; 39 | response.write("^_^\n\rhello jsEncrypt!"); 40 | response.close(); 41 | } 42 | }catch(e){ 43 | console.log('\n-----------------Error Info--------------------') 44 | var fullMessage = "Message: "+e.toString() + ':'+ e.line; 45 | for (var p in e) { 46 | fullMessage += "\n" + p.toUpperCase() + ": " + e[p]; 47 | } 48 | console.log(fullMessage); 49 | console.log('---------------------------------------------') 50 | console.log('[*] phantomJS exit!') 51 | phantom.exit(); 52 | } 53 | }); -------------------------------------------------------------------------------- /test/TestScript/sha1/sha1.js: -------------------------------------------------------------------------------- 1 | /* 2 | * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined 3 | * in FIPS PUB 180-1 4 | * Version 2.1-BETA Copyright Paul Johnston 2000 - 2002. 5 | * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet 6 | * Distributed under the BSD License 7 | * See http://pajhome.org.uk/crypt/md5 for details. 8 | */ 9 | /* 10 | * Configurable variables. You may need to tweak these to be compatible with 11 | * the server-side, but the defaults work in most cases. 12 | */ 13 | var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */ 14 | var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */ 15 | var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */ 16 | 17 | /* 18 | * These are the functions you'll usually want to call 19 | * They take string arguments and return either hex or base-64 encoded strings 20 | */ 21 | function hex_sha1(s) { 22 | return binb2hex(core_sha1(str2binb(s), s.length * chrsz)); 23 | } 24 | 25 | function b64_sha1(s) { 26 | return binb2b64(core_sha1(str2binb(s), s.length * chrsz)); 27 | } 28 | 29 | function str_sha1(s) { 30 | return binb2str(core_sha1(str2binb(s), s.length * chrsz)); 31 | } 32 | 33 | function hex_hmac_sha1(key, data) { 34 | return binb2hex(core_hmac_sha1(key, data)); 35 | } 36 | 37 | function b64_hmac_sha1(key, data) { 38 | return binb2b64(core_hmac_sha1(key, data)); 39 | } 40 | 41 | function str_hmac_sha1(key, data) { 42 | return binb2str(core_hmac_sha1(key, data)); 43 | } 44 | 45 | /* 46 | * Perform a simple self-test to see if the VM is working 47 | */ 48 | function sha1_vm_test() { 49 | return hex_sha1("abc") == "a9993e364706816aba3e25717850c26c9cd0d89d"; 50 | } 51 | 52 | /* 53 | * Calculate the SHA-1 of an array of big-endian words, and a bit length 54 | */ 55 | function core_sha1(x, len) { 56 | /* append padding */ 57 | x[len >> 5] |= 0x80 << (24 - len % 32); 58 | x[((len + 64 >> 9) << 4) + 15] = len; 59 | 60 | var w = Array(80); 61 | var a = 1732584193; 62 | var b = -271733879; 63 | var c = -1732584194; 64 | var d = 271733878; 65 | var e = -1009589776; 66 | 67 | for (var i = 0; i < x.length; i += 16) { 68 | var olda = a; 69 | var oldb = b; 70 | var oldc = c; 71 | var oldd = d; 72 | var olde = e; 73 | 74 | for (var j = 0; j < 80; j++) { 75 | if (j < 16) w[j] = x[i + j]; 76 | else w[j] = rol(w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16], 1); 77 | var t = safe_add(safe_add(rol(a, 5), sha1_ft(j, b, c, d)), safe_add(safe_add(e, w[j]), sha1_kt(j))); 78 | e = d; 79 | d = c; 80 | c = rol(b, 30); 81 | b = a; 82 | a = t; 83 | } 84 | 85 | a = safe_add(a, olda); 86 | b = safe_add(b, oldb); 87 | c = safe_add(c, oldc); 88 | d = safe_add(d, oldd); 89 | e = safe_add(e, olde); 90 | } 91 | return Array(a, b, c, d, e); 92 | 93 | } 94 | 95 | /* 96 | * Perform the appropriate triplet combination function for the current 97 | * iteration 98 | */ 99 | function sha1_ft(t, b, c, d) { 100 | if (t < 20) return (b & c) | ((~b) & d); 101 | if (t < 40) return b ^ c ^ d; 102 | if (t < 60) return (b & c) | (b & d) | (c & d); 103 | return b ^ c ^ d; 104 | } 105 | 106 | /* 107 | * Determine the appropriate additive constant for the current iteration 108 | */ 109 | function sha1_kt(t) { 110 | return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 : (t < 60) ? -1894007588 : -899497514; 111 | } 112 | 113 | /* 114 | * Calculate the HMAC-SHA1 of a key and some data 115 | */ 116 | function core_hmac_sha1(key, data) { 117 | var bkey = str2binb(key); 118 | if (bkey.length > 16) bkey = core_sha1(bkey, key.length * chrsz); 119 | 120 | var ipad = Array(16), 121 | opad = Array(16); 122 | for (var i = 0; i < 16; i++) { 123 | ipad[i] = bkey[i] ^ 0x36363636; 124 | opad[i] = bkey[i] ^ 0x5C5C5C5C; 125 | } 126 | 127 | var hash = core_sha1(ipad.concat(str2binb(data)), 512 + data.length * chrsz); 128 | return core_sha1(opad.concat(hash), 512 + 160); 129 | } 130 | 131 | /* 132 | * Add integers, wrapping at 2^32. This uses 16-bit operations internally 133 | * to work around bugs in some JS interpreters. 134 | */ 135 | function safe_add(x, y) { 136 | var lsw = (x & 0xFFFF) + (y & 0xFFFF); 137 | var msw = (x >> 16) + (y >> 16) + (lsw >> 16); 138 | return (msw << 16) | (lsw & 0xFFFF); 139 | } 140 | 141 | /* 142 | * Bitwise rotate a 32-bit number to the left. 143 | */ 144 | function rol(num, cnt) { 145 | return (num << cnt) | (num >>> (32 - cnt)); 146 | } 147 | 148 | /* 149 | * Convert an 8-bit or 16-bit string to an array of big-endian words 150 | * In 8-bit function, characters >255 have their hi-byte silently ignored. 151 | */ 152 | function str2binb(str) { 153 | var bin = Array(); 154 | var mask = (1 << chrsz) - 1; 155 | for (var i = 0; i < str.length * chrsz; i += chrsz) 156 | bin[i >> 5] |= (str.charCodeAt(i / chrsz) & mask) << (24 - i % 32); 157 | return bin; 158 | } 159 | 160 | /* 161 | * Convert an array of big-endian words to a string 162 | */ 163 | function binb2str(bin) { 164 | var str = ""; 165 | var mask = (1 << chrsz) - 1; 166 | for (var i = 0; i < bin.length * 32; i += chrsz) 167 | str += String.fromCharCode((bin[i >> 5] >>> (24 - i % 32)) & mask); 168 | return str; 169 | } 170 | 171 | /* 172 | * Convert an array of big-endian words to a hex string. 173 | */ 174 | function binb2hex(binarray) { 175 | var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef"; 176 | var str = ""; 177 | for (var i = 0; i < binarray.length * 4; i++) { 178 | str += hex_tab.charAt((binarray[i >> 2] >> ((3 - i % 4) * 8 + 4)) & 0xF) + hex_tab.charAt((binarray[i >> 2] >> ((3 - i % 4) * 8)) & 0xF); 179 | } 180 | return str; 181 | } 182 | 183 | /* 184 | * Convert an array of big-endian words to a base-64 string 185 | */ 186 | function binb2b64(binarray) { 187 | var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 188 | var str = ""; 189 | for (var i = 0; i < binarray.length * 4; i += 3) { 190 | var triplet = (((binarray[i >> 2] >> 8 * (3 - i % 4)) & 0xFF) << 16) | (((binarray[i + 1 >> 2] >> 8 * (3 - (i + 1) % 4)) & 0xFF) << 8) | ((binarray[i + 2 >> 2] >> 8 * (3 - (i + 2) % 4)) & 0xFF); 191 | for (var j = 0; j < 4; j++) { 192 | if (i * 8 + j * 6 > binarray.length * 32) str += b64pad; 193 | else str += tab.charAt((triplet >> 6 * (3 - j)) & 0x3F); 194 | } 195 | } 196 | return str; 197 | } -------------------------------------------------------------------------------- /test/TestScript/sha256/jsEncrypter_sha256.js: -------------------------------------------------------------------------------- 1 | var webserver = require('webserver'); 2 | server = webserver.create(); 3 | 4 | var host = '127.0.0.1'; 5 | var port = '1664'; 6 | 7 | // 加载实现加密算法的js脚本 8 | var wasSuccessful = phantom.injectJs('crypto-js.js');/* 引入实现加密的js文件*/ 9 | 10 | // 处理函数 11 | function js_encrypt(payload){ 12 | var newpayload; 13 | /**********在这里编写调用加密函数进行加密的代码************/ 14 | newpayload = CryptoJS.SHA256(payload); 15 | /**********************************************************/ 16 | return newpayload; 17 | } 18 | 19 | 20 | if(wasSuccessful){ 21 | console.log("[*] load js successful"); 22 | console.log("[!] ^_^"); 23 | console.log("[*] jsEncrypterJS start!"); 24 | console.log("[+] address: http://"+host+":"+port); 25 | }else{ 26 | console.log('[*] load js fail!'); 27 | } 28 | 29 | var service = server.listen(host+':'+port,function(request, response){ 30 | try{ 31 | if(request.method == 'POST'){ 32 | var payload = request.post['payload']; 33 | var encrypt_payload = js_encrypt(payload); 34 | console.log('[+] ' + payload + ':' + encrypt_payload); 35 | response.statusCode = 200; 36 | response.write(encrypt_payload.toString()); 37 | response.close(); 38 | }else{ 39 | response.statusCode = 200; 40 | response.write("^_^\n\rhello jsEncrypter!"); 41 | response.close(); 42 | } 43 | }catch(e){ 44 | console.log('\n-----------------Error Info--------------------') 45 | var fullMessage = "Message: "+e.toString() + ':'+ e.line; 46 | for (var p in e) { 47 | fullMessage += "\n" + p.toUpperCase() + ": " + e[p]; 48 | } 49 | console.log(fullMessage); 50 | console.log('---------------------------------------------') 51 | console.log('[*] phantomJS exit!') 52 | phantom.exit(); 53 | } 54 | }); -------------------------------------------------------------------------------- /test/TestScript/sha384/jsEncrypter_sha384.js: -------------------------------------------------------------------------------- 1 | var webserver = require('webserver'); 2 | server = webserver.create(); 3 | 4 | var host = '127.0.0.1'; 5 | var port = '1664'; 6 | 7 | // 加载实现加密算法的js脚本 8 | var wasSuccessful = phantom.injectJs('crypto-js.js');/*引入实现加密的js文件*/ 9 | 10 | // 处理函数 11 | function js_encrypt(payload){ 12 | var newpayload; 13 | /**********在这里编写调用加密函数进行加密的代码************/ 14 | newpayload = CryptoJS.SHA384(payload); 15 | /**********************************************************/ 16 | return newpayload; 17 | } 18 | 19 | if(wasSuccessful){ 20 | console.log("[*] load js successful"); 21 | console.log("[!] ^_^"); 22 | console.log("[*] jsEncrypterJS start!"); 23 | console.log("[+] address: http://"+host+":"+port); 24 | }else{ 25 | console.log('[*] load js fail!'); 26 | } 27 | 28 | var service = server.listen(host+':'+port,function(request, response){ 29 | try{ 30 | if(request.method == 'POST'){ 31 | var payload = request.post['payload']; 32 | var encrypt_payload = js_encrypt(payload); 33 | console.log('[+] ' + payload + ':' + encrypt_payload); 34 | response.statusCode = 200; 35 | response.write(encrypt_payload.toString()); 36 | response.close(); 37 | }else{ 38 | response.statusCode = 200; 39 | response.write("^_^\n\rhello jsEncrypter!"); 40 | response.close(); 41 | } 42 | }catch(e){ 43 | console.log('\n-----------------Error Info--------------------') 44 | var fullMessage = "Message: "+e.toString() + ':'+ e.line; 45 | for (var p in e) { 46 | fullMessage += "\n" + p.toUpperCase() + ": " + e[p]; 47 | } 48 | console.log(fullMessage); 49 | console.log('---------------------------------------------') 50 | console.log('[*] phantomJS exit!') 51 | phantom.exit(); 52 | } 53 | }); -------------------------------------------------------------------------------- /test/TestScript/sha512/jsEncrypter_sha512.js: -------------------------------------------------------------------------------- 1 | var webserver = require('webserver'); 2 | server = webserver.create(); 3 | 4 | var host = '127.0.0.1'; 5 | var port = '1664'; 6 | 7 | // 加载实现加密算法的js脚本 8 | var wasSuccessful = phantom.injectJs('crypto-js.js');/*引入实现加密的js文件*/ 9 | 10 | // 处理函数 11 | function js_encrypt(payload){ 12 | var newpayload; 13 | /**********在这里编写调用加密函数进行加密的代码************/ 14 | newpayload = CryptoJS.SHA512(payload); 15 | /**********************************************************/ 16 | return newpayload; 17 | } 18 | 19 | if(wasSuccessful){ 20 | console.log("[*] load js successful"); 21 | console.log("[!] ^_^"); 22 | console.log("[*] jsEncrypterJS start!"); 23 | console.log("[+] address: http://"+host+":"+port); 24 | }else{ 25 | console.log('[*] load js fail!'); 26 | } 27 | 28 | var service = server.listen(host+':'+port,function(request, response){ 29 | try{ 30 | if(request.method == 'POST'){ 31 | var payload = request.post['payload']; 32 | var encrypt_payload = js_encrypt(payload); 33 | console.log('[+] ' + payload + ':' + encrypt_payload); 34 | console.log(encrypt_payload); 35 | response.statusCode = 200; 36 | response.write(encrypt_payload.toString()); 37 | response.close(); 38 | }else{ 39 | response.statusCode = 200; 40 | response.write("^_^\n\rhello jsEncrypter!"); 41 | response.close(); 42 | } 43 | }catch(e){ 44 | console.log('\n-----------------Error Info--------------------') 45 | var fullMessage = "Message: "+e.toString() + ':'+ e.line; 46 | for (var p in e) { 47 | fullMessage += "\n" + p.toUpperCase() + ": " + e[p]; 48 | } 49 | console.log(fullMessage); 50 | console.log('---------------------------------------------') 51 | console.log('[*] phantomJS exit!') 52 | phantom.exit(); 53 | } 54 | }); -------------------------------------------------------------------------------- /test/webapp/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 密码加密传输Demo 5 | 6 | 7 | 8 | 9 | 10 | 59 | 60 | 61 | 62 |
63 | 64 | 65 | 66 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 90 | 91 | 92 |
encrypt: 67 | 76 |
username:
password:
88 | 89 |
93 |
94 | 95 | -------------------------------------------------------------------------------- /test/webapp/js/base64.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Base64 encode / decode 4 | * 5 | * @author haitao.tu 6 | * @date 2010-04-26 7 | * @email tuhaitao@foxmail.com 8 | * 9 | */ 10 | 11 | function Base64() { 12 | 13 | // private property 14 | _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; 15 | 16 | // public method for encoding 17 | this.encode = function (input) { 18 | var output = ""; 19 | var chr1, chr2, chr3, enc1, enc2, enc3, enc4; 20 | var i = 0; 21 | input = _utf8_encode(input); 22 | while (i < input.length) { 23 | chr1 = input.charCodeAt(i++); 24 | chr2 = input.charCodeAt(i++); 25 | chr3 = input.charCodeAt(i++); 26 | enc1 = chr1 >> 2; 27 | enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); 28 | enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); 29 | enc4 = chr3 & 63; 30 | if (isNaN(chr2)) { 31 | enc3 = enc4 = 64; 32 | } else if (isNaN(chr3)) { 33 | enc4 = 64; 34 | } 35 | output = output + 36 | _keyStr.charAt(enc1) + _keyStr.charAt(enc2) + 37 | _keyStr.charAt(enc3) + _keyStr.charAt(enc4); 38 | } 39 | return output; 40 | } 41 | 42 | // public method for decoding 43 | this.decode = function (input) { 44 | var output = ""; 45 | var chr1, chr2, chr3; 46 | var enc1, enc2, enc3, enc4; 47 | var i = 0; 48 | input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); 49 | while (i < input.length) { 50 | enc1 = _keyStr.indexOf(input.charAt(i++)); 51 | enc2 = _keyStr.indexOf(input.charAt(i++)); 52 | enc3 = _keyStr.indexOf(input.charAt(i++)); 53 | enc4 = _keyStr.indexOf(input.charAt(i++)); 54 | chr1 = (enc1 << 2) | (enc2 >> 4); 55 | chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); 56 | chr3 = ((enc3 & 3) << 6) | enc4; 57 | output = output + String.fromCharCode(chr1); 58 | if (enc3 != 64) { 59 | output = output + String.fromCharCode(chr2); 60 | } 61 | if (enc4 != 64) { 62 | output = output + String.fromCharCode(chr3); 63 | } 64 | } 65 | output = _utf8_decode(output); 66 | return output; 67 | } 68 | 69 | // private method for UTF-8 encoding 70 | _utf8_encode = function (string) { 71 | string = string.replace(/\r\n/g,"\n"); 72 | var utftext = ""; 73 | for (var n = 0; n < string.length; n++) { 74 | var c = string.charCodeAt(n); 75 | if (c < 128) { 76 | utftext += String.fromCharCode(c); 77 | } else if((c > 127) && (c < 2048)) { 78 | utftext += String.fromCharCode((c >> 6) | 192); 79 | utftext += String.fromCharCode((c & 63) | 128); 80 | } else { 81 | utftext += String.fromCharCode((c >> 12) | 224); 82 | utftext += String.fromCharCode(((c >> 6) & 63) | 128); 83 | utftext += String.fromCharCode((c & 63) | 128); 84 | } 85 | 86 | } 87 | return utftext; 88 | } 89 | 90 | // private method for UTF-8 decoding 91 | _utf8_decode = function (utftext) { 92 | var string = ""; 93 | var i = 0; 94 | var c = c1 = c2 = 0; 95 | while ( i < utftext.length ) { 96 | c = utftext.charCodeAt(i); 97 | if (c < 128) { 98 | string += String.fromCharCode(c); 99 | i++; 100 | } else if((c > 191) && (c < 224)) { 101 | c2 = utftext.charCodeAt(i+1); 102 | string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); 103 | i += 2; 104 | } else { 105 | c2 = utftext.charCodeAt(i+1); 106 | c3 = utftext.charCodeAt(i+2); 107 | string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); 108 | i += 3; 109 | } 110 | } 111 | return string; 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /test/webapp/js/jsencrypt.js: -------------------------------------------------------------------------------- 1 | var JSEncryptExports = {}; 2 | (function(exports) { 3 | function BigInteger(a,b,c){null!=a&&("number"==typeof a?this.fromNumber(a,b,c):null==b&&"string"!=typeof a?this.fromString(a,256):this.fromString(a,b))}function nbi(){return new BigInteger(null)}function am1(a,b,c,d,e,f){for(;--f>=0;){var g=b*this[a++]+c[d]+e;e=Math.floor(g/67108864),c[d++]=67108863&g}return e}function am2(a,b,c,d,e,f){for(var g=32767&b,h=b>>15;--f>=0;){var i=32767&this[a],j=this[a++]>>15,k=h*i+j*g;i=g*i+((32767&k)<<15)+c[d]+(1073741823&e),e=(i>>>30)+(k>>>15)+h*j+(e>>>30),c[d++]=1073741823&i}return e}function am3(a,b,c,d,e,f){for(var g=16383&b,h=b>>14;--f>=0;){var i=16383&this[a],j=this[a++]>>14,k=h*i+j*g;i=g*i+((16383&k)<<14)+c[d]+e,e=(i>>28)+(k>>14)+h*j,c[d++]=268435455&i}return e}function int2char(a){return BI_RM.charAt(a)}function intAt(a,b){var c=BI_RC[a.charCodeAt(b)];return null==c?-1:c}function bnpCopyTo(a){for(var b=this.t-1;b>=0;--b)a[b]=this[b];a.t=this.t,a.s=this.s}function bnpFromInt(a){this.t=1,this.s=0>a?-1:0,a>0?this[0]=a:-1>a?this[0]=a+DV:this.t=0}function nbv(a){var b=nbi();return b.fromInt(a),b}function bnpFromString(a,b){var c;if(16==b)c=4;else if(8==b)c=3;else if(256==b)c=8;else if(2==b)c=1;else if(32==b)c=5;else{if(4!=b)return void this.fromRadix(a,b);c=2}this.t=0,this.s=0;for(var d=a.length,e=!1,f=0;--d>=0;){var g=8==c?255&a[d]:intAt(a,d);0>g?"-"==a.charAt(d)&&(e=!0):(e=!1,0==f?this[this.t++]=g:f+c>this.DB?(this[this.t-1]|=(g&(1<>this.DB-f):this[this.t-1]|=g<=this.DB&&(f-=this.DB))}8==c&&0!=(128&a[0])&&(this.s=-1,f>0&&(this[this.t-1]|=(1<0&&this[this.t-1]==a;)--this.t}function bnToString(a){if(this.s<0)return"-"+this.negate().toString(a);var b;if(16==a)b=4;else if(8==a)b=3;else if(2==a)b=1;else if(32==a)b=5;else{if(4!=a)return this.toRadix(a);b=2}var c,d=(1<0)for(h>h)>0&&(e=!0,f=int2char(c));g>=0;)b>h?(c=(this[g]&(1<>(h+=this.DB-b)):(c=this[g]>>(h-=b)&d,0>=h&&(h+=this.DB,--g)),c>0&&(e=!0),e&&(f+=int2char(c));return e?f:"0"}function bnNegate(){var a=nbi();return BigInteger.ZERO.subTo(this,a),a}function bnAbs(){return this.s<0?this.negate():this}function bnCompareTo(a){var b=this.s-a.s;if(0!=b)return b;var c=this.t;if(b=c-a.t,0!=b)return this.s<0?-b:b;for(;--c>=0;)if(0!=(b=this[c]-a[c]))return b;return 0}function nbits(a){var b,c=1;return 0!=(b=a>>>16)&&(a=b,c+=16),0!=(b=a>>8)&&(a=b,c+=8),0!=(b=a>>4)&&(a=b,c+=4),0!=(b=a>>2)&&(a=b,c+=2),0!=(b=a>>1)&&(a=b,c+=1),c}function bnBitLength(){return this.t<=0?0:this.DB*(this.t-1)+nbits(this[this.t-1]^this.s&this.DM)}function bnpDLShiftTo(a,b){var c;for(c=this.t-1;c>=0;--c)b[c+a]=this[c];for(c=a-1;c>=0;--c)b[c]=0;b.t=this.t+a,b.s=this.s}function bnpDRShiftTo(a,b){for(var c=a;c=0;--c)b[c+g+1]=this[c]>>e|h,h=(this[c]&f)<=0;--c)b[c]=0;b[g]=h,b.t=this.t+g+1,b.s=this.s,b.clamp()}function bnpRShiftTo(a,b){b.s=this.s;var c=Math.floor(a/this.DB);if(c>=this.t)return void(b.t=0);var d=a%this.DB,e=this.DB-d,f=(1<>d;for(var g=c+1;g>d;d>0&&(b[this.t-c-1]|=(this.s&f)<c;)d+=this[c]-a[c],b[c++]=d&this.DM,d>>=this.DB;if(a.t>=this.DB;d+=this.s}else{for(d+=this.s;c>=this.DB;d-=a.s}b.s=0>d?-1:0,-1>d?b[c++]=this.DV+d:d>0&&(b[c++]=d),b.t=c,b.clamp()}function bnpMultiplyTo(a,b){var c=this.abs(),d=a.abs(),e=c.t;for(b.t=e+d.t;--e>=0;)b[e]=0;for(e=0;e=0;)a[c]=0;for(c=0;c=b.DV&&(a[c+b.t]-=b.DV,a[c+b.t+1]=1)}a.t>0&&(a[a.t-1]+=b.am(c,b[c],a,2*c,0,1)),a.s=0,a.clamp()}function bnpDivRemTo(a,b,c){var d=a.abs();if(!(d.t<=0)){var e=this.abs();if(e.t0?(d.lShiftTo(i,f),e.lShiftTo(i,c)):(d.copyTo(f),e.copyTo(c));var j=f.t,k=f[j-1];if(0!=k){var l=k*(1<1?f[j-2]>>this.F2:0),m=this.FV/l,n=(1<=0&&(c[c.t++]=1,c.subTo(r,c)),BigInteger.ONE.dlShiftTo(j,r),r.subTo(f,f);f.t=0;){var s=c[--p]==k?this.DM:Math.floor(c[p]*m+(c[p-1]+o)*n);if((c[p]+=f.am(0,s,c,q,0,j))0&&c.rShiftTo(i,c),0>g&&BigInteger.ZERO.subTo(c,c)}}}function bnMod(a){var b=nbi();return this.abs().divRemTo(a,null,b),this.s<0&&b.compareTo(BigInteger.ZERO)>0&&a.subTo(b,b),b}function Classic(a){this.m=a}function cConvert(a){return a.s<0||a.compareTo(this.m)>=0?a.mod(this.m):a}function cRevert(a){return a}function cReduce(a){a.divRemTo(this.m,null,a)}function cMulTo(a,b,c){a.multiplyTo(b,c),this.reduce(c)}function cSqrTo(a,b){a.squareTo(b),this.reduce(b)}function bnpInvDigit(){if(this.t<1)return 0;var a=this[0];if(0==(1&a))return 0;var b=3&a;return b=b*(2-(15&a)*b)&15,b=b*(2-(255&a)*b)&255,b=b*(2-((65535&a)*b&65535))&65535,b=b*(2-a*b%this.DV)%this.DV,b>0?this.DV-b:-b}function Montgomery(a){this.m=a,this.mp=a.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<0&&this.m.subTo(b,b),b}function montRevert(a){var b=nbi();return a.copyTo(b),this.reduce(b),b}function montReduce(a){for(;a.t<=this.mt2;)a[a.t++]=0;for(var b=0;b>15)*this.mpl&this.um)<<15)&a.DM;for(c=b+this.m.t,a[c]+=this.m.am(0,d,a,b,0,this.m.t);a[c]>=a.DV;)a[c]-=a.DV,a[++c]++}a.clamp(),a.drShiftTo(this.m.t,a),a.compareTo(this.m)>=0&&a.subTo(this.m,a)}function montSqrTo(a,b){a.squareTo(b),this.reduce(b)}function montMulTo(a,b,c){a.multiplyTo(b,c),this.reduce(c)}function bnpIsEven(){return 0==(this.t>0?1&this[0]:this.s)}function bnpExp(a,b){if(a>4294967295||1>a)return BigInteger.ONE;var c=nbi(),d=nbi(),e=b.convert(this),f=nbits(a)-1;for(e.copyTo(c);--f>=0;)if(b.sqrTo(c,d),(a&1<0)b.mulTo(d,e,c);else{var g=c;c=d,d=g}return b.revert(c)}function bnModPowInt(a,b){var c;return c=256>a||b.isEven()?new Classic(b):new Montgomery(b),this.exp(a,c)}function bnClone(){var a=nbi();return this.copyTo(a),a}function bnIntValue(){if(this.s<0){if(1==this.t)return this[0]-this.DV;if(0==this.t)return-1}else{if(1==this.t)return this[0];if(0==this.t)return 0}return(this[1]&(1<<32-this.DB)-1)<>24}function bnShortValue(){return 0==this.t?this.s:this[0]<<16>>16}function bnpChunkSize(a){return Math.floor(Math.LN2*this.DB/Math.log(a))}function bnSigNum(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1}function bnpToRadix(a){if(null==a&&(a=10),0==this.signum()||2>a||a>36)return"0";var b=this.chunkSize(a),c=Math.pow(a,b),d=nbv(c),e=nbi(),f=nbi(),g="";for(this.divRemTo(d,e,f);e.signum()>0;)g=(c+f.intValue()).toString(a).substr(1)+g,e.divRemTo(d,e,f);return f.intValue().toString(a)+g}function bnpFromRadix(a,b){this.fromInt(0),null==b&&(b=10);for(var c=this.chunkSize(b),d=Math.pow(b,c),e=!1,f=0,g=0,h=0;hi?"-"==a.charAt(h)&&0==this.signum()&&(e=!0):(g=b*g+i,++f>=c&&(this.dMultiply(d),this.dAddOffset(g,0),f=0,g=0))}f>0&&(this.dMultiply(Math.pow(b,f)),this.dAddOffset(g,0)),e&&BigInteger.ZERO.subTo(this,this)}function bnpFromNumber(a,b,c){if("number"==typeof b)if(2>a)this.fromInt(1);else for(this.fromNumber(a,c),this.testBit(a-1)||this.bitwiseTo(BigInteger.ONE.shiftLeft(a-1),op_or,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(b);)this.dAddOffset(2,0),this.bitLength()>a&&this.subTo(BigInteger.ONE.shiftLeft(a-1),this);else{var d=new Array,e=7&a;d.length=(a>>3)+1,b.nextBytes(d),e>0?d[0]&=(1<0)for(d>d)!=(this.s&this.DM)>>d&&(b[e++]=c|this.s<=0;)8>d?(c=(this[a]&(1<>(d+=this.DB-8)):(c=this[a]>>(d-=8)&255,0>=d&&(d+=this.DB,--a)),0!=(128&c)&&(c|=-256),0==e&&(128&this.s)!=(128&c)&&++e,(e>0||c!=this.s)&&(b[e++]=c);return b}function bnEquals(a){return 0==this.compareTo(a)}function bnMin(a){return this.compareTo(a)<0?this:a}function bnMax(a){return this.compareTo(a)>0?this:a}function bnpBitwiseTo(a,b,c){var d,e,f=Math.min(a.t,this.t);for(d=0;f>d;++d)c[d]=b(this[d],a[d]);if(a.ta?this.rShiftTo(-a,b):this.lShiftTo(a,b),b}function bnShiftRight(a){var b=nbi();return 0>a?this.lShiftTo(-a,b):this.rShiftTo(a,b),b}function lbit(a){if(0==a)return-1;var b=0;return 0==(65535&a)&&(a>>=16,b+=16),0==(255&a)&&(a>>=8,b+=8),0==(15&a)&&(a>>=4,b+=4),0==(3&a)&&(a>>=2,b+=2),0==(1&a)&&++b,b}function bnGetLowestSetBit(){for(var a=0;a=this.t?0!=this.s:0!=(this[b]&1<c;)d+=this[c]+a[c],b[c++]=d&this.DM,d>>=this.DB;if(a.t>=this.DB;d+=this.s}else{for(d+=this.s;c>=this.DB;d+=a.s}b.s=0>d?-1:0,d>0?b[c++]=d:-1>d&&(b[c++]=this.DV+d),b.t=c,b.clamp()}function bnAdd(a){var b=nbi();return this.addTo(a,b),b}function bnSubtract(a){var b=nbi();return this.subTo(a,b),b}function bnMultiply(a){var b=nbi();return this.multiplyTo(a,b),b}function bnSquare(){var a=nbi();return this.squareTo(a),a}function bnDivide(a){var b=nbi();return this.divRemTo(a,b,null),b}function bnRemainder(a){var b=nbi();return this.divRemTo(a,null,b),b}function bnDivideAndRemainder(a){var b=nbi(),c=nbi();return this.divRemTo(a,b,c),new Array(b,c)}function bnpDMultiply(a){this[this.t]=this.am(0,a-1,this,0,0,this.t),++this.t,this.clamp()}function bnpDAddOffset(a,b){if(0!=a){for(;this.t<=b;)this[this.t++]=0;for(this[b]+=a;this[b]>=this.DV;)this[b]-=this.DV,++b>=this.t&&(this[this.t++]=0),++this[b]}}function NullExp(){}function nNop(a){return a}function nMulTo(a,b,c){a.multiplyTo(b,c)}function nSqrTo(a,b){a.squareTo(b)}function bnPow(a){return this.exp(a,new NullExp)}function bnpMultiplyLowerTo(a,b,c){var d=Math.min(this.t+a.t,b);for(c.s=0,c.t=d;d>0;)c[--d]=0;var e;for(e=c.t-this.t;e>d;++d)c[d+this.t]=this.am(0,a[d],c,d,0,this.t);for(e=Math.min(a.t,b);e>d;++d)this.am(0,a[d],c,d,0,b-d);c.clamp()}function bnpMultiplyUpperTo(a,b,c){--b;var d=c.t=this.t+a.t-b;for(c.s=0;--d>=0;)c[d]=0;for(d=Math.max(b-this.t,0);d2*this.m.t)return a.mod(this.m);if(a.compareTo(this.m)<0)return a;var b=nbi();return a.copyTo(b),this.reduce(b),b}function barrettRevert(a){return a}function barrettReduce(a){for(a.drShiftTo(this.m.t-1,this.r2),a.t>this.m.t+1&&(a.t=this.m.t+1,a.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);a.compareTo(this.r2)<0;)a.dAddOffset(1,this.m.t+1);for(a.subTo(this.r2,a);a.compareTo(this.m)>=0;)a.subTo(this.m,a)}function barrettSqrTo(a,b){a.squareTo(b),this.reduce(b)}function barrettMulTo(a,b,c){a.multiplyTo(b,c),this.reduce(c)}function bnModPow(a,b){var c,d,e=a.bitLength(),f=nbv(1);if(0>=e)return f;c=18>e?1:48>e?3:144>e?4:768>e?5:6,d=8>e?new Classic(b):b.isEven()?new Barrett(b):new Montgomery(b);var g=new Array,h=3,i=c-1,j=(1<1){var k=nbi();for(d.sqrTo(g[1],k);j>=h;)g[h]=nbi(),d.mulTo(k,g[h-2],g[h]),h+=2}var l,m,n=a.t-1,o=!0,p=nbi();for(e=nbits(a[n])-1;n>=0;){for(e>=i?l=a[n]>>e-i&j:(l=(a[n]&(1<0&&(l|=a[n-1]>>this.DB+e-i)),h=c;0==(1&l);)l>>=1,--h;if((e-=h)<0&&(e+=this.DB,--n),o)g[l].copyTo(f),o=!1;else{for(;h>1;)d.sqrTo(f,p),d.sqrTo(p,f),h-=2;h>0?d.sqrTo(f,p):(m=f,f=p,p=m),d.mulTo(p,g[l],f)}for(;n>=0&&0==(a[n]&1<f)return b;for(f>e&&(f=e),f>0&&(b.rShiftTo(f,b),c.rShiftTo(f,c));b.signum()>0;)(e=b.getLowestSetBit())>0&&b.rShiftTo(e,b),(e=c.getLowestSetBit())>0&&c.rShiftTo(e,c),b.compareTo(c)>=0?(b.subTo(c,b),b.rShiftTo(1,b)):(c.subTo(b,c),c.rShiftTo(1,c));return f>0&&c.lShiftTo(f,c),c}function bnpModInt(a){if(0>=a)return 0;var b=this.DV%a,c=this.s<0?a-1:0;if(this.t>0)if(0==b)c=this[0]%a;else for(var d=this.t-1;d>=0;--d)c=(b*c+this[d])%a;return c}function bnModInverse(a){var b=a.isEven();if(this.isEven()&&b||0==a.signum())return BigInteger.ZERO;for(var c=a.clone(),d=this.clone(),e=nbv(1),f=nbv(0),g=nbv(0),h=nbv(1);0!=c.signum();){for(;c.isEven();)c.rShiftTo(1,c),b?(e.isEven()&&f.isEven()||(e.addTo(this,e),f.subTo(a,f)),e.rShiftTo(1,e)):f.isEven()||f.subTo(a,f),f.rShiftTo(1,f);for(;d.isEven();)d.rShiftTo(1,d),b?(g.isEven()&&h.isEven()||(g.addTo(this,g),h.subTo(a,h)),g.rShiftTo(1,g)):h.isEven()||h.subTo(a,h),h.rShiftTo(1,h);c.compareTo(d)>=0?(c.subTo(d,c),b&&e.subTo(g,e),f.subTo(h,f)):(d.subTo(c,d),b&&g.subTo(e,g),h.subTo(f,h))}return 0!=d.compareTo(BigInteger.ONE)?BigInteger.ZERO:h.compareTo(a)>=0?h.subtract(a):h.signum()<0?(h.addTo(a,h),h.signum()<0?h.add(a):h):h}function bnIsProbablePrime(a){var b,c=this.abs();if(1==c.t&&c[0]<=lowprimes[lowprimes.length-1]){for(b=0;bd;)d*=lowprimes[e++];for(d=c.modInt(d);e>b;)if(d%lowprimes[b++]==0)return!1}return c.millerRabin(a)}function bnpMillerRabin(a){var b=this.subtract(BigInteger.ONE),c=b.getLowestSetBit();if(0>=c)return!1;var d=b.shiftRight(c);a=a+1>>1,a>lowprimes.length&&(a=lowprimes.length);for(var e=nbi(),f=0;a>f;++f){e.fromInt(lowprimes[Math.floor(Math.random()*lowprimes.length)]);var g=e.modPow(d,this);if(0!=g.compareTo(BigInteger.ONE)&&0!=g.compareTo(b)){for(var h=1;h++b;++b)this.S[b]=b;for(c=0,b=0;256>b;++b)c=c+this.S[b]+a[b%a.length]&255,d=this.S[b],this.S[b]=this.S[c],this.S[c]=d;this.i=0,this.j=0}function ARC4next(){var a;return this.i=this.i+1&255,this.j=this.j+this.S[this.i]&255,a=this.S[this.i],this.S[this.i]=this.S[this.j],this.S[this.j]=a,this.S[a+this.S[this.i]&255]}function prng_newstate(){return new Arcfour}function rng_get_byte(){if(null==rng_state){for(rng_state=prng_newstate();rng_psize>rng_pptr;){var a=Math.floor(65536*Math.random());rng_pool[rng_pptr++]=255&a}for(rng_state.init(rng_pool),rng_pptr=0;rng_pptra?"0"+a.toString(16):a.toString(16)}function pkcs1pad2(a,b){if(b=0&&b>0;){var e=a.charCodeAt(d--);128>e?c[--b]=e:e>127&&2048>e?(c[--b]=63&e|128,c[--b]=e>>6|192):(c[--b]=63&e|128,c[--b]=e>>6&63|128,c[--b]=e>>12|224)}c[--b]=0;for(var f=new SecureRandom,g=new Array;b>2;){for(g[0]=0;0==g[0];)f.nextBytes(g);c[--b]=g[0]}return c[--b]=2,c[--b]=0,new BigInteger(c)}function RSAKey(){this.n=null,this.e=0,this.d=null,this.p=null,this.q=null,this.dmp1=null,this.dmq1=null,this.coeff=null}function RSASetPublic(a,b){null!=a&&null!=b&&a.length>0&&b.length>0?(this.n=parseBigInt(a,16),this.e=parseInt(b,16)):console.error("Invalid RSA public key")}function RSADoPublic(a){return a.modPowInt(this.e,this.n)}function RSAEncrypt(a){var b=pkcs1pad2(a,this.n.bitLength()+7>>3);if(null==b)return null;var c=this.doPublic(b);if(null==c)return null;var d=c.toString(16);return 0==(1&d.length)?d:"0"+d}function pkcs1unpad2(a,b){for(var c=a.toByteArray(),d=0;d=c.length)return null;for(var e="";++df?e+=String.fromCharCode(f):f>191&&224>f?(e+=String.fromCharCode((31&f)<<6|63&c[d+1]),++d):(e+=String.fromCharCode((15&f)<<12|(63&c[d+1])<<6|63&c[d+2]),d+=2)}return e}function RSASetPrivate(a,b,c){null!=a&&null!=b&&a.length>0&&b.length>0?(this.n=parseBigInt(a,16),this.e=parseInt(b,16),this.d=parseBigInt(c,16)):console.error("Invalid RSA private key")}function RSASetPrivateEx(a,b,c,d,e,f,g,h){null!=a&&null!=b&&a.length>0&&b.length>0?(this.n=parseBigInt(a,16),this.e=parseInt(b,16),this.d=parseBigInt(c,16),this.p=parseBigInt(d,16),this.q=parseBigInt(e,16),this.dmp1=parseBigInt(f,16),this.dmq1=parseBigInt(g,16),this.coeff=parseBigInt(h,16)):console.error("Invalid RSA private key")}function RSAGenerate(a,b){var c=new SecureRandom,d=a>>1;this.e=parseInt(b,16);for(var e=new BigInteger(b,16);;){for(;this.p=new BigInteger(a-d,1,c),0!=this.p.subtract(BigInteger.ONE).gcd(e).compareTo(BigInteger.ONE)||!this.p.isProbablePrime(10););for(;this.q=new BigInteger(d,1,c),0!=this.q.subtract(BigInteger.ONE).gcd(e).compareTo(BigInteger.ONE)||!this.q.isProbablePrime(10););if(this.p.compareTo(this.q)<=0){var f=this.p;this.p=this.q,this.q=f}var g=this.p.subtract(BigInteger.ONE),h=this.q.subtract(BigInteger.ONE),i=g.multiply(h);if(0==i.gcd(e).compareTo(BigInteger.ONE)){this.n=this.p.multiply(this.q),this.d=e.modInverse(i),this.dmp1=this.d.mod(g),this.dmq1=this.d.mod(h),this.coeff=this.q.modInverse(this.p);break}}}function RSADoPrivate(a){if(null==this.p||null==this.q)return a.modPow(this.d,this.n);for(var b=a.mod(this.p).modPow(this.dmp1,this.p),c=a.mod(this.q).modPow(this.dmq1,this.q);b.compareTo(c)<0;)b=b.add(this.p);return b.subtract(c).multiply(this.coeff).mod(this.p).multiply(this.q).add(c)}function RSADecrypt(a){var b=parseBigInt(a,16),c=this.doPrivate(b);return null==c?null:pkcs1unpad2(c,this.n.bitLength()+7>>3)}function hex2b64(a){var b,c,d="";for(b=0;b+3<=a.length;b+=3)c=parseInt(a.substring(b,b+3),16),d+=b64map.charAt(c>>6)+b64map.charAt(63&c);for(b+1==a.length?(c=parseInt(a.substring(b,b+1),16),d+=b64map.charAt(c<<2)):b+2==a.length&&(c=parseInt(a.substring(b,b+2),16),d+=b64map.charAt(c>>2)+b64map.charAt((3&c)<<4));(3&d.length)>0;)d+=b64pad;return d}function b64tohex(a){var b,c,d="",e=0;for(b=0;b>2),c=3&v,e=1):1==e?(d+=int2char(c<<2|v>>4),c=15&v,e=2):2==e?(d+=int2char(c),d+=int2char(v>>2),c=3&v,e=3):(d+=int2char(c<<2|v>>4),d+=int2char(15&v),e=0));return 1==e&&(d+=int2char(c<<2)),d}function b64toBA(a){var b,c=b64tohex(a),d=new Array;for(b=0;2*b=vv;++vv)BI_RC[rr++]=vv;for(rr="a".charCodeAt(0),vv=10;36>vv;++vv)BI_RC[rr++]=vv;for(rr="A".charCodeAt(0),vv=10;36>vv;++vv)BI_RC[rr++]=vv;Classic.prototype.convert=cConvert,Classic.prototype.revert=cRevert,Classic.prototype.reduce=cReduce,Classic.prototype.mulTo=cMulTo,Classic.prototype.sqrTo=cSqrTo,Montgomery.prototype.convert=montConvert,Montgomery.prototype.revert=montRevert,Montgomery.prototype.reduce=montReduce,Montgomery.prototype.mulTo=montMulTo,Montgomery.prototype.sqrTo=montSqrTo,BigInteger.prototype.copyTo=bnpCopyTo,BigInteger.prototype.fromInt=bnpFromInt,BigInteger.prototype.fromString=bnpFromString,BigInteger.prototype.clamp=bnpClamp,BigInteger.prototype.dlShiftTo=bnpDLShiftTo,BigInteger.prototype.drShiftTo=bnpDRShiftTo,BigInteger.prototype.lShiftTo=bnpLShiftTo,BigInteger.prototype.rShiftTo=bnpRShiftTo,BigInteger.prototype.subTo=bnpSubTo,BigInteger.prototype.multiplyTo=bnpMultiplyTo,BigInteger.prototype.squareTo=bnpSquareTo,BigInteger.prototype.divRemTo=bnpDivRemTo,BigInteger.prototype.invDigit=bnpInvDigit,BigInteger.prototype.isEven=bnpIsEven,BigInteger.prototype.exp=bnpExp,BigInteger.prototype.toString=bnToString,BigInteger.prototype.negate=bnNegate,BigInteger.prototype.abs=bnAbs,BigInteger.prototype.compareTo=bnCompareTo,BigInteger.prototype.bitLength=bnBitLength,BigInteger.prototype.mod=bnMod,BigInteger.prototype.modPowInt=bnModPowInt,BigInteger.ZERO=nbv(0),BigInteger.ONE=nbv(1),NullExp.prototype.convert=nNop,NullExp.prototype.revert=nNop,NullExp.prototype.mulTo=nMulTo,NullExp.prototype.sqrTo=nSqrTo,Barrett.prototype.convert=barrettConvert,Barrett.prototype.revert=barrettRevert,Barrett.prototype.reduce=barrettReduce,Barrett.prototype.mulTo=barrettMulTo,Barrett.prototype.sqrTo=barrettSqrTo;var lowprimes=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],lplim=(1<<26)/lowprimes[lowprimes.length-1];BigInteger.prototype.chunkSize=bnpChunkSize,BigInteger.prototype.toRadix=bnpToRadix,BigInteger.prototype.fromRadix=bnpFromRadix,BigInteger.prototype.fromNumber=bnpFromNumber,BigInteger.prototype.bitwiseTo=bnpBitwiseTo,BigInteger.prototype.changeBit=bnpChangeBit,BigInteger.prototype.addTo=bnpAddTo,BigInteger.prototype.dMultiply=bnpDMultiply,BigInteger.prototype.dAddOffset=bnpDAddOffset,BigInteger.prototype.multiplyLowerTo=bnpMultiplyLowerTo,BigInteger.prototype.multiplyUpperTo=bnpMultiplyUpperTo,BigInteger.prototype.modInt=bnpModInt,BigInteger.prototype.millerRabin=bnpMillerRabin,BigInteger.prototype.clone=bnClone,BigInteger.prototype.intValue=bnIntValue,BigInteger.prototype.byteValue=bnByteValue,BigInteger.prototype.shortValue=bnShortValue,BigInteger.prototype.signum=bnSigNum,BigInteger.prototype.toByteArray=bnToByteArray,BigInteger.prototype.equals=bnEquals,BigInteger.prototype.min=bnMin,BigInteger.prototype.max=bnMax,BigInteger.prototype.and=bnAnd,BigInteger.prototype.or=bnOr,BigInteger.prototype.xor=bnXor,BigInteger.prototype.andNot=bnAndNot,BigInteger.prototype.not=bnNot,BigInteger.prototype.shiftLeft=bnShiftLeft,BigInteger.prototype.shiftRight=bnShiftRight,BigInteger.prototype.getLowestSetBit=bnGetLowestSetBit,BigInteger.prototype.bitCount=bnBitCount,BigInteger.prototype.testBit=bnTestBit,BigInteger.prototype.setBit=bnSetBit,BigInteger.prototype.clearBit=bnClearBit,BigInteger.prototype.flipBit=bnFlipBit,BigInteger.prototype.add=bnAdd,BigInteger.prototype.subtract=bnSubtract,BigInteger.prototype.multiply=bnMultiply,BigInteger.prototype.divide=bnDivide,BigInteger.prototype.remainder=bnRemainder,BigInteger.prototype.divideAndRemainder=bnDivideAndRemainder,BigInteger.prototype.modPow=bnModPow,BigInteger.prototype.modInverse=bnModInverse,BigInteger.prototype.pow=bnPow,BigInteger.prototype.gcd=bnGCD,BigInteger.prototype.isProbablePrime=bnIsProbablePrime,BigInteger.prototype.square=bnSquare,Arcfour.prototype.init=ARC4init,Arcfour.prototype.next=ARC4next;var rng_psize=256,rng_state,rng_pool,rng_pptr;if(null==rng_pool){rng_pool=new Array,rng_pptr=0;var t;if(window.crypto&&window.crypto.getRandomValues){var z=new Uint32Array(256);for(window.crypto.getRandomValues(z),t=0;t=256||rng_pptr>=rng_psize)return void(window.removeEventListener?window.removeEventListener("mousemove",onMouseMoveListener):window.detachEvent&&window.detachEvent("onmousemove",onMouseMoveListener));this.count+=1;var b=a.x+a.y;rng_pool[rng_pptr++]=255&b};window.addEventListener?window.addEventListener("mousemove",onMouseMoveListener):window.attachEvent&&window.attachEvent("onmousemove",onMouseMoveListener)}SecureRandom.prototype.nextBytes=rng_get_bytes,RSAKey.prototype.doPublic=RSADoPublic,RSAKey.prototype.setPublic=RSASetPublic,RSAKey.prototype.encrypt=RSAEncrypt,RSAKey.prototype.doPrivate=RSADoPrivate,RSAKey.prototype.setPrivate=RSASetPrivate,RSAKey.prototype.setPrivateEx=RSASetPrivateEx,RSAKey.prototype.generate=RSAGenerate,RSAKey.prototype.decrypt=RSADecrypt,function(){var a=function(a,b,c){var d=new SecureRandom,e=a>>1;this.e=parseInt(b,16);var f=new BigInteger(b,16),g=this,h=function(){var b=function(){if(g.p.compareTo(g.q)<=0){var a=g.p;g.p=g.q,g.q=a}var b=g.p.subtract(BigInteger.ONE),d=g.q.subtract(BigInteger.ONE),e=b.multiply(d);0==e.gcd(f).compareTo(BigInteger.ONE)?(g.n=g.p.multiply(g.q),g.d=f.modInverse(e),g.dmp1=g.d.mod(b),g.dmq1=g.d.mod(d),g.coeff=g.q.modInverse(g.p),setTimeout(function(){c()},0)):setTimeout(h,0)},i=function(){g.q=nbi(),g.q.fromNumberAsync(e,1,d,function(){g.q.subtract(BigInteger.ONE).gcda(f,function(a){0==a.compareTo(BigInteger.ONE)&&g.q.isProbablePrime(10)?setTimeout(b,0):setTimeout(i,0)})})},j=function(){g.p=nbi(),g.p.fromNumberAsync(a-e,1,d,function(){g.p.subtract(BigInteger.ONE).gcda(f,function(a){0==a.compareTo(BigInteger.ONE)&&g.p.isProbablePrime(10)?setTimeout(i,0):setTimeout(j,0)})})};setTimeout(j,0)};setTimeout(h,0)};RSAKey.prototype.generateAsync=a;var b=function(a,b){var c=this.s<0?this.negate():this.clone(),d=a.s<0?a.negate():a.clone();if(c.compareTo(d)<0){var e=c;c=d,d=e}var f=c.getLowestSetBit(),g=d.getLowestSetBit();if(0>g)return void b(c);g>f&&(g=f),g>0&&(c.rShiftTo(g,c),d.rShiftTo(g,d));var h=function(){(f=c.getLowestSetBit())>0&&c.rShiftTo(f,c),(f=d.getLowestSetBit())>0&&d.rShiftTo(f,d),c.compareTo(d)>=0?(c.subTo(d,c),c.rShiftTo(1,c)):(d.subTo(c,d),d.rShiftTo(1,d)),c.signum()>0?setTimeout(h,0):(g>0&&d.lShiftTo(g,d),setTimeout(function(){b(d)},0))};setTimeout(h,10)};BigInteger.prototype.gcda=b;var c=function(a,b,c,d){if("number"==typeof b)if(2>a)this.fromInt(1);else{this.fromNumber(a,c),this.testBit(a-1)||this.bitwiseTo(BigInteger.ONE.shiftLeft(a-1),op_or,this),this.isEven()&&this.dAddOffset(1,0);var e=this,f=function(){e.dAddOffset(2,0),e.bitLength()>a&&e.subTo(BigInteger.ONE.shiftLeft(a-1),e),e.isProbablePrime(b)?setTimeout(function(){d()},0):setTimeout(f,0)};setTimeout(f,0)}else{var g=new Array,h=7&a;g.length=(a>>3)+1,b.nextBytes(g),h>0?g[0]&=(1<f;f++)e+="f";var g=new BigInteger(e,16),h=g.xor(a).add(BigInteger.ONE);b=h.toString(16).replace(/^-/,"")}return b},this.getPEMStringFromHex=function(a,b){var c=CryptoJS.enc.Hex.parse(a),d=CryptoJS.enc.Base64.stringify(c),e=d.replace(/(.{64})/g,"$1\r\n");return e=e.replace(/\r\n$/,""),"-----BEGIN "+b+"-----\r\n"+e+"\r\n-----END "+b+"-----\r\n"}},KJUR.asn1.ASN1Object=function(){var a="";this.getLengthHexFromValue=function(){if("undefined"==typeof this.hV||null==this.hV)throw"this.hV is null or undefined.";if(this.hV.length%2==1)throw"value hex must be even length: n="+a.length+",v="+this.hV;var b=this.hV.length/2,c=b.toString(16);if(c.length%2==1&&(c="0"+c),128>b)return c;var d=c.length/2;if(d>15)throw"ASN.1 length too long to represent by 8x: n = "+b.toString(16);var e=128+d;return e.toString(16)+c},this.getEncodedHex=function(){return(null==this.hTLV||this.isModified)&&(this.hV=this.getFreshValueHex(),this.hL=this.getLengthHexFromValue(),this.hTLV=this.hT+this.hL+this.hV,this.isModified=!1),this.hTLV},this.getValueHex=function(){return this.getEncodedHex(),this.hV},this.getFreshValueHex=function(){return""}},KJUR.asn1.DERAbstractString=function(a){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);this.getString=function(){return this.s},this.setString=function(a){this.hTLV=null,this.isModified=!0,this.s=a,this.hV=stohex(this.s)},this.setStringHex=function(a){this.hTLV=null,this.isModified=!0,this.s=null,this.hV=a},this.getFreshValueHex=function(){return this.hV},"undefined"!=typeof a&&("undefined"!=typeof a.str?this.setString(a.str):"undefined"!=typeof a.hex&&this.setStringHex(a.hex))},JSX.extend(KJUR.asn1.DERAbstractString,KJUR.asn1.ASN1Object),KJUR.asn1.DERAbstractTime=function(){KJUR.asn1.DERAbstractTime.superclass.constructor.call(this);this.localDateToUTC=function(a){utc=a.getTime()+6e4*a.getTimezoneOffset();var b=new Date(utc);return b},this.formatDate=function(a,b){var c=this.zeroPadding,d=this.localDateToUTC(a),e=String(d.getFullYear());"utc"==b&&(e=e.substr(2,2));var f=c(String(d.getMonth()+1),2),g=c(String(d.getDate()),2),h=c(String(d.getHours()),2),i=c(String(d.getMinutes()),2),j=c(String(d.getSeconds()),2);return e+f+g+h+i+j+"Z"},this.zeroPadding=function(a,b){return a.length>=b?a:new Array(b-a.length+1).join("0")+a},this.getString=function(){return this.s},this.setString=function(a){this.hTLV=null,this.isModified=!0,this.s=a,this.hV=stohex(this.s)},this.setByDateValue=function(a,b,c,d,e,f){var g=new Date(Date.UTC(a,b-1,c,d,e,f,0));this.setByDate(g)},this.getFreshValueHex=function(){return this.hV}},JSX.extend(KJUR.asn1.DERAbstractTime,KJUR.asn1.ASN1Object),KJUR.asn1.DERAbstractStructured=function(a){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);this.setByASN1ObjectArray=function(a){this.hTLV=null,this.isModified=!0,this.asn1Array=a},this.appendASN1Object=function(a){this.hTLV=null,this.isModified=!0,this.asn1Array.push(a)},this.asn1Array=new Array,"undefined"!=typeof a&&"undefined"!=typeof a.array&&(this.asn1Array=a.array)},JSX.extend(KJUR.asn1.DERAbstractStructured,KJUR.asn1.ASN1Object),KJUR.asn1.DERBoolean=function(){KJUR.asn1.DERBoolean.superclass.constructor.call(this),this.hT="01",this.hTLV="0101ff"},JSX.extend(KJUR.asn1.DERBoolean,KJUR.asn1.ASN1Object),KJUR.asn1.DERInteger=function(a){KJUR.asn1.DERInteger.superclass.constructor.call(this),this.hT="02",this.setByBigInteger=function(a){this.hTLV=null,this.isModified=!0,this.hV=KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(a)},this.setByInteger=function(a){var b=new BigInteger(String(a),10);this.setByBigInteger(b)},this.setValueHex=function(a){this.hV=a},this.getFreshValueHex=function(){return this.hV},"undefined"!=typeof a&&("undefined"!=typeof a.bigint?this.setByBigInteger(a.bigint):"undefined"!=typeof a["int"]?this.setByInteger(a["int"]):"undefined"!=typeof a.hex&&this.setValueHex(a.hex))},JSX.extend(KJUR.asn1.DERInteger,KJUR.asn1.ASN1Object),KJUR.asn1.DERBitString=function(a){KJUR.asn1.DERBitString.superclass.constructor.call(this),this.hT="03",this.setHexValueIncludingUnusedBits=function(a){this.hTLV=null,this.isModified=!0,this.hV=a},this.setUnusedBitsAndHexValue=function(a,b){if(0>a||a>7)throw"unused bits shall be from 0 to 7: u = "+a;var c="0"+a;this.hTLV=null,this.isModified=!0,this.hV=c+b},this.setByBinaryString=function(a){a=a.replace(/0+$/,"");var b=8-a.length%8;8==b&&(b=0);for(var c=0;b>=c;c++)a+="0";for(var d="",c=0;cc;c++)b[c]=!1;return b},this.getFreshValueHex=function(){return this.hV},"undefined"!=typeof a&&("undefined"!=typeof a.hex?this.setHexValueIncludingUnusedBits(a.hex):"undefined"!=typeof a.bin?this.setByBinaryString(a.bin):"undefined"!=typeof a.array&&this.setByBooleanArray(a.array))},JSX.extend(KJUR.asn1.DERBitString,KJUR.asn1.ASN1Object),KJUR.asn1.DEROctetString=function(a){KJUR.asn1.DEROctetString.superclass.constructor.call(this,a),this.hT="04"},JSX.extend(KJUR.asn1.DEROctetString,KJUR.asn1.DERAbstractString),KJUR.asn1.DERNull=function(){KJUR.asn1.DERNull.superclass.constructor.call(this),this.hT="05",this.hTLV="0500"},JSX.extend(KJUR.asn1.DERNull,KJUR.asn1.ASN1Object),KJUR.asn1.DERObjectIdentifier=function(a){var b=function(a){var b=a.toString(16);return 1==b.length&&(b="0"+b),b},c=function(a){var c="",d=new BigInteger(a,10),e=d.toString(2),f=7-e.length%7;7==f&&(f=0);for(var g="",h=0;f>h;h++)g+="0";e=g+e;for(var h=0;hd;++d)b[e.charAt(d)]=d;for(e=e.toLowerCase(),d=10;16>d;++d)b[e.charAt(d)]=d;for(d=0;d=2?(g[g.length]=h,h=0,i=0):h<<=4}}if(i)throw"Hex encoding incomplete: 4 bits missing";return g},window.Hex=c}(),function(a){"use strict";var b,c={};c.decode=function(c){var d;if(b===a){var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",f="= \f\n\r \u2028\u2029";for(b=[],d=0;64>d;++d)b[e.charAt(d)]=d;for(d=0;d=4?(g[g.length]=h>>16,g[g.length]=h>>8&255,g[g.length]=255&h,h=0,i=0):h<<=6}}switch(i){case 1:throw"Base64 encoding incomplete: at least 2 bits missing";case 2:g[g.length]=h>>10;break;case 3:g[g.length]=h>>16,g[g.length]=h>>8&255}return g},c.re=/-----BEGIN [^-]+-----([A-Za-z0-9+\/=\s]+)-----END [^-]+-----|begin-base64[^\n]+\n([A-Za-z0-9+\/=\s]+)====/,c.unarmor=function(a){var b=c.re.exec(a);if(b)if(b[1])a=b[1];else{if(!b[2])throw"RegExp out of sync";a=b[2]}return c.decode(a)},window.Base64=c}(),function(a){"use strict";function b(a,c){a instanceof b?(this.enc=a.enc,this.pos=a.pos):(this.enc=a,this.pos=c)}function c(a,b,c,d,e){this.stream=a,this.header=b,this.length=c,this.tag=d,this.sub=e}var d=100,e="…",f={tag:function(a,b){var c=document.createElement(a);return c.className=b,c},text:function(a){return document.createTextNode(a)}};b.prototype.get=function(b){if(b===a&&(b=this.pos++),b>=this.enc.length)throw"Requesting byte offset "+b+" on a stream of length "+this.enc.length;return this.enc[b]},b.prototype.hexDigits="0123456789ABCDEF",b.prototype.hexByte=function(a){return this.hexDigits.charAt(a>>4&15)+this.hexDigits.charAt(15&a)},b.prototype.hexDump=function(a,b,c){for(var d="",e=a;b>e;++e)if(d+=this.hexByte(this.get(e)),c!==!0)switch(15&e){case 7:d+=" ";break;case 15:d+="\n";break;default:d+=" "}return d},b.prototype.parseStringISO=function(a,b){for(var c="",d=a;b>d;++d)c+=String.fromCharCode(this.get(d));return c},b.prototype.parseStringUTF=function(a,b){for(var c="",d=a;b>d;){var e=this.get(d++);c+=String.fromCharCode(128>e?e:e>191&&224>e?(31&e)<<6|63&this.get(d++):(15&e)<<12|(63&this.get(d++))<<6|63&this.get(d++))}return c},b.prototype.parseStringBMP=function(a,b){for(var c="",d=a;b>d;d+=2){var e=this.get(d),f=this.get(d+1);c+=String.fromCharCode((e<<8)+f)}return c},b.prototype.reTime=/^((?:1[89]|2\d)?\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|[-+](?:[0]\d|1[0-2])([0-5]\d)?)?$/,b.prototype.parseTime=function(a,b){var c=this.parseStringISO(a,b),d=this.reTime.exec(c);return d?(c=d[1]+"-"+d[2]+"-"+d[3]+" "+d[4],d[5]&&(c+=":"+d[5],d[6]&&(c+=":"+d[6],d[7]&&(c+="."+d[7]))),d[8]&&(c+=" UTC","Z"!=d[8]&&(c+=d[8],d[9]&&(c+=":"+d[9]))),c):"Unrecognized time: "+c},b.prototype.parseInteger=function(a,b){var c=b-a;if(c>4){c<<=3;var d=this.get(a);if(0===d)c-=8;else for(;128>d;)d<<=1,--c;return"("+c+" bit)"}for(var e=0,f=a;b>f;++f)e=e<<8|this.get(f);return e},b.prototype.parseBitString=function(a,b){var c=this.get(a),d=(b-a-1<<3)-c,e="("+d+" bit)";if(20>=d){var f=c;e+=" ";for(var g=b-1;g>a;--g){for(var h=this.get(g),i=f;8>i;++i)e+=h>>i&1?"1":"0";f=0}}return e},b.prototype.parseOctetString=function(a,b){var c=b-a,f="("+c+" byte) ";c>d&&(b=a+d);for(var g=a;b>g;++g)f+=this.hexByte(this.get(g));return c>d&&(f+=e),f},b.prototype.parseOID=function(a,b){for(var c="",d=0,e=0,f=a;b>f;++f){var g=this.get(f);if(d=d<<7|127&g,e+=7,!(128&g)){if(""===c){var h=80>d?40>d?0:1:2;c=h+"."+(d-40*h)}else c+="."+(e>=31?"bigint":d);d=e=0}}return c},c.prototype.typeName=function(){if(this.tag===a)return"unknown";var b=this.tag>>6,c=(this.tag>>5&1,31&this.tag);switch(b){case 0:switch(c){case 0:return"EOC";case 1:return"BOOLEAN";case 2:return"INTEGER";case 3:return"BIT_STRING";case 4:return"OCTET_STRING";case 5:return"NULL";case 6:return"OBJECT_IDENTIFIER";case 7:return"ObjectDescriptor";case 8:return"EXTERNAL";case 9:return"REAL";case 10:return"ENUMERATED";case 11:return"EMBEDDED_PDV";case 12:return"UTF8String";case 16:return"SEQUENCE";case 17:return"SET";case 18:return"NumericString";case 19:return"PrintableString";case 20:return"TeletexString";case 21:return"VideotexString";case 22:return"IA5String";case 23:return"UTCTime";case 24:return"GeneralizedTime";case 25:return"GraphicString";case 26:return"VisibleString";case 27:return"GeneralString";case 28:return"UniversalString";case 30:return"BMPString";default:return"Universal_"+c.toString(16)}case 1:return"Application_"+c.toString(16);case 2:return"["+c+"]";case 3:return"Private_"+c.toString(16)}},c.prototype.reSeemsASCII=/^[ -~]+$/,c.prototype.content=function(){if(this.tag===a)return null;var b=this.tag>>6,c=31&this.tag,f=this.posContent(),g=Math.abs(this.length);if(0!==b){if(null!==this.sub)return"("+this.sub.length+" elem)";var h=this.stream.parseStringISO(f,f+Math.min(g,d));return this.reSeemsASCII.test(h)?h.substring(0,2*d)+(h.length>2*d?e:""):this.stream.parseOctetString(f,f+g)}switch(c){case 1:return 0===this.stream.get(f)?"false":"true";case 2:return this.stream.parseInteger(f,f+g);case 3:return this.sub?"("+this.sub.length+" elem)":this.stream.parseBitString(f,f+g);case 4:return this.sub?"("+this.sub.length+" elem)":this.stream.parseOctetString(f,f+g);case 6:return this.stream.parseOID(f,f+g);case 16:case 17:return"("+this.sub.length+" elem)";case 12:return this.stream.parseStringUTF(f,f+g);case 18:case 19:case 20:case 21:case 22:case 26:return this.stream.parseStringISO(f,f+g);case 30:return this.stream.parseStringBMP(f,f+g);case 23:case 24:return this.stream.parseTime(f,f+g)}return null},c.prototype.toString=function(){return this.typeName()+"@"+this.stream.pos+"[header:"+this.header+",length:"+this.length+",sub:"+(null===this.sub?"null":this.sub.length)+"]"},c.prototype.print=function(b){if(b===a&&(b=""),document.writeln(b+this),null!==this.sub){b+=" ";for(var c=0,d=this.sub.length;d>c;++c)this.sub[c].print(b)}},c.prototype.toPrettyString=function(b){b===a&&(b="");var c=b+this.typeName()+" @"+this.stream.pos;if(this.length>=0&&(c+="+"),c+=this.length,32&this.tag?c+=" (constructed)":3!=this.tag&&4!=this.tag||null===this.sub||(c+=" (encapsulates)"),c+="\n",null!==this.sub){b+=" ";for(var d=0,e=this.sub.length;e>d;++d)c+=this.sub[d].toPrettyString(b)}return c},c.prototype.toDOM=function(){var a=f.tag("div","node");a.asn1=this;var b=f.tag("div","head"),c=this.typeName().replace(/_/g," ");b.innerHTML=c;var d=this.content();if(null!==d){d=String(d).replace(/",c+="Length: "+this.header+"+",c+=this.length>=0?this.length:-this.length+" (undefined)",32&this.tag?c+="
(constructed)":3!=this.tag&&4!=this.tag||null===this.sub||(c+="
(encapsulates)"),null!==d&&(c+="
Value:
"+d+"","object"==typeof oids&&6==this.tag)){var h=oids[d];h&&(h.d&&(c+="
"+h.d),h.c&&(c+="
"+h.c),h.w&&(c+="
(warning!)"))}g.innerHTML=c,a.appendChild(g);var i=f.tag("div","sub");if(null!==this.sub)for(var j=0,k=this.sub.length;k>j;++j)i.appendChild(this.sub[j].toDOM());return a.appendChild(i),b.onclick=function(){a.className="node collapsed"==a.className?"node":"node collapsed"},a},c.prototype.posStart=function(){return this.stream.pos},c.prototype.posContent=function(){return this.stream.pos+this.header},c.prototype.posEnd=function(){return this.stream.pos+this.header+Math.abs(this.length)},c.prototype.fakeHover=function(a){this.node.className+=" hover",a&&(this.head.className+=" hover")},c.prototype.fakeOut=function(a){var b=/ ?hover/;this.node.className=this.node.className.replace(b,""),a&&(this.head.className=this.head.className.replace(b,""))},c.prototype.toHexDOM_sub=function(a,b,c,d,e){if(!(d>=e)){var g=f.tag("span",b);g.appendChild(f.text(c.hexDump(d,e))),a.appendChild(g)}},c.prototype.toHexDOM=function(b){var c=f.tag("span","hex");if(b===a&&(b=c),this.head.hexNode=c,this.head.onmouseover=function(){this.hexNode.className="hexCurrent"},this.head.onmouseout=function(){this.hexNode.className="hex"},c.asn1=this,c.onmouseover=function(){var a=!b.selected;a&&(b.selected=this.asn1,this.className="hexCurrent"),this.asn1.fakeHover(a)},c.onmouseout=function(){var a=b.selected==this.asn1;this.asn1.fakeOut(a),a&&(b.selected=null,this.className="hex")},this.toHexDOM_sub(c,"tag",this.stream,this.posStart(),this.posStart()+1),this.toHexDOM_sub(c,this.length>=0?"dlen":"ulen",this.stream,this.posStart()+1,this.posContent()),null===this.sub)c.appendChild(f.text(this.stream.hexDump(this.posContent(),this.posEnd())));else if(this.sub.length>0){var d=this.sub[0],e=this.sub[this.sub.length-1];this.toHexDOM_sub(c,"intro",this.stream,this.posContent(),d.posStart());for(var g=0,h=this.sub.length;h>g;++g)c.appendChild(this.sub[g].toHexDOM(b));this.toHexDOM_sub(c,"outro",this.stream,e.posEnd(),this.posEnd())}return c},c.prototype.toHexString=function(){return this.stream.hexDump(this.posStart(),this.posEnd(),!0)},c.decodeLength=function(a){var b=a.get(),c=127&b;if(c==b)return c;if(c>3)throw"Length over 24 bits not supported at position "+(a.pos-1);if(0===c)return-1;b=0;for(var d=0;c>d;++d)b=b<<8|a.get();return b},c.hasContent=function(a,d,e){if(32&a)return!0;if(3>a||a>4)return!1;var f=new b(e);3==a&&f.get();var g=f.get();if(g>>6&1)return!1;try{var h=c.decodeLength(f);return f.pos-e.pos+h==d}catch(i){return!1}},c.decode=function(a){a instanceof b||(a=new b(a,0));var d=new b(a),e=a.get(),f=c.decodeLength(a),g=a.pos-d.pos,h=null;if(c.hasContent(e,f,a)){var i=a.pos;if(3==e&&a.get(),h=[],f>=0){for(var j=i+f;a.posd;++d){var f=new b(a[d].value,0),g=c.decodeLength(f);g!=a[d].expected&&document.write("In test["+d+"] expected "+a[d].expected+" got "+g+"\n")}},window.ASN1=c}(),ASN1.prototype.getHexStringValue=function(){var a=this.toHexString(),b=2*this.header,c=2*this.length;return a.substr(b,c)},RSAKey.prototype.parseKey=function(a){try{var b=0,c=0,d=/^\s*(?:[0-9A-Fa-f][0-9A-Fa-f]\s*)+$/,e=d.test(a)?Hex.decode(a):Base64.unarmor(a),f=ASN1.decode(e);if(3===f.sub.length&&(f=f.sub[2].sub[0]),9===f.sub.length){b=f.sub[1].getHexStringValue(),this.n=parseBigInt(b,16),c=f.sub[2].getHexStringValue(),this.e=parseInt(c,16);var g=f.sub[3].getHexStringValue();this.d=parseBigInt(g,16);var h=f.sub[4].getHexStringValue();this.p=parseBigInt(h,16);var i=f.sub[5].getHexStringValue();this.q=parseBigInt(i,16);var j=f.sub[6].getHexStringValue();this.dmp1=parseBigInt(j,16);var k=f.sub[7].getHexStringValue();this.dmq1=parseBigInt(k,16);var l=f.sub[8].getHexStringValue();this.coeff=parseBigInt(l,16)}else{if(2!==f.sub.length)return!1;var m=f.sub[1],n=m.sub[0];b=n.sub[0].getHexStringValue(),this.n=parseBigInt(b,16),c=n.sub[1].getHexStringValue(),this.e=parseInt(c,16)}return!0}catch(o){return!1}},RSAKey.prototype.getPrivateBaseKey=function(){var a={array:[new KJUR.asn1.DERInteger({"int":0}),new KJUR.asn1.DERInteger({bigint:this.n}),new KJUR.asn1.DERInteger({"int":this.e}),new KJUR.asn1.DERInteger({bigint:this.d}),new KJUR.asn1.DERInteger({bigint:this.p}),new KJUR.asn1.DERInteger({bigint:this.q}),new KJUR.asn1.DERInteger({bigint:this.dmp1}),new KJUR.asn1.DERInteger({bigint:this.dmq1}),new KJUR.asn1.DERInteger({bigint:this.coeff})]},b=new KJUR.asn1.DERSequence(a);return b.getEncodedHex()},RSAKey.prototype.getPrivateBaseKeyB64=function(){return hex2b64(this.getPrivateBaseKey())},RSAKey.prototype.getPublicBaseKey=function(){var a={array:[new KJUR.asn1.DERObjectIdentifier({oid:"1.2.840.113549.1.1.1"}),new KJUR.asn1.DERNull]},b=new KJUR.asn1.DERSequence(a);a={array:[new KJUR.asn1.DERInteger({bigint:this.n}),new KJUR.asn1.DERInteger({"int":this.e})]};var c=new KJUR.asn1.DERSequence(a);a={hex:"00"+c.getEncodedHex()};var d=new KJUR.asn1.DERBitString(a);a={array:[b,d]};var e=new KJUR.asn1.DERSequence(a);return e.getEncodedHex()},RSAKey.prototype.getPublicBaseKeyB64=function(){return hex2b64(this.getPublicBaseKey())},RSAKey.prototype.wordwrap=function(a,b){if(b=b||64,!a)return a;var c="(.{1,"+b+"})( +|$\n?)|(.{1,"+b+"})";return a.match(RegExp(c,"g")).join("\n")},RSAKey.prototype.getPrivateKey=function(){var a="-----BEGIN RSA PRIVATE KEY-----\n";return a+=this.wordwrap(this.getPrivateBaseKeyB64())+"\n",a+="-----END RSA PRIVATE KEY-----"},RSAKey.prototype.getPublicKey=function(){var a="-----BEGIN PUBLIC KEY-----\n";return a+=this.wordwrap(this.getPublicBaseKeyB64())+"\n",a+="-----END PUBLIC KEY-----"},RSAKey.prototype.hasPublicKeyProperty=function(a){return a=a||{},a.hasOwnProperty("n")&&a.hasOwnProperty("e")},RSAKey.prototype.hasPrivateKeyProperty=function(a){return a=a||{},a.hasOwnProperty("n")&&a.hasOwnProperty("e")&&a.hasOwnProperty("d")&&a.hasOwnProperty("p")&&a.hasOwnProperty("q")&&a.hasOwnProperty("dmp1")&&a.hasOwnProperty("dmq1")&&a.hasOwnProperty("coeff")},RSAKey.prototype.parsePropertiesFrom=function(a){this.n=a.n,this.e=a.e,a.hasOwnProperty("d")&&(this.d=a.d,this.p=a.p,this.q=a.q,this.dmp1=a.dmp1,this.dmq1=a.dmq1,this.coeff=a.coeff)};var JSEncryptRSAKey=function(a){RSAKey.call(this),a&&("string"==typeof a?this.parseKey(a):(this.hasPrivateKeyProperty(a)||this.hasPublicKeyProperty(a))&&this.parsePropertiesFrom(a))};JSEncryptRSAKey.prototype=new RSAKey,JSEncryptRSAKey.prototype.constructor=JSEncryptRSAKey;var JSEncrypt=function(a){a=a||{},this.default_key_size=parseInt(a.default_key_size)||1024,this.default_public_exponent=a.default_public_exponent||"010001",this.log=a.log||!1,this.key=null};JSEncrypt.prototype.setKey=function(a){this.log&&this.key&&console.warn("A key was already set, overriding existing."),this.key=new JSEncryptRSAKey(a)},JSEncrypt.prototype.setPrivateKey=function(a){this.setKey(a)},JSEncrypt.prototype.setPublicKey=function(a){this.setKey(a)},JSEncrypt.prototype.decrypt=function(a){try{return this.getKey().decrypt(b64tohex(a))}catch(b){return!1}},JSEncrypt.prototype.encrypt=function(a){try{return hex2b64(this.getKey().encrypt(a))}catch(b){return!1}},JSEncrypt.prototype.getKey=function(a){if(!this.key){if(this.key=new JSEncryptRSAKey,a&&"[object Function]"==={}.toString.call(a))return void this.key.generateAsync(this.default_key_size,this.default_public_exponent,a);this.key.generate(this.default_key_size,this.default_public_exponent)}return this.key},JSEncrypt.prototype.getPrivateKey=function(){return this.getKey().getPrivateKey()},JSEncrypt.prototype.getPrivateKeyB64=function(){return this.getKey().getPrivateBaseKeyB64()},JSEncrypt.prototype.getPublicKey=function(){return this.getKey().getPublicKey()},JSEncrypt.prototype.getPublicKeyB64=function(){return this.getKey().getPublicBaseKeyB64()};exports.JSEncrypt = JSEncrypt; 5 | })(JSEncryptExports); 6 | var JSEncrypt = JSEncryptExports.JSEncrypt; 7 | -------------------------------------------------------------------------------- /test/webapp/js/md5.js: -------------------------------------------------------------------------------- 1 | /* 2 | * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message 3 | * Digest Algorithm, as defined in RFC 1321. 4 | * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002. 5 | * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet 6 | * Distributed under the BSD License 7 | * See http://pajhome.org.uk/crypt/md5 for more info. 8 | */ 9 | 10 | /* 11 | * Configurable variables. You may need to tweak these to be compatible with 12 | * the server-side, but the defaults work in most cases. 13 | */ 14 | var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */ 15 | var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */ 16 | var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */ 17 | 18 | /* 19 | * These are the functions you'll usually want to call 20 | * They take string arguments and return either hex or base-64 encoded strings 21 | */ 22 | function hex_md5(s){ return binl2hex(core_md5(str2binl(s), s.length * chrsz));} 23 | function b64_md5(s){ return binl2b64(core_md5(str2binl(s), s.length * chrsz));} 24 | function str_md5(s){ return binl2str(core_md5(str2binl(s), s.length * chrsz));} 25 | function hex_hmac_md5(key, data) { return binl2hex(core_hmac_md5(key, data)); } 26 | function b64_hmac_md5(key, data) { return binl2b64(core_hmac_md5(key, data)); } 27 | function str_hmac_md5(key, data) { return binl2str(core_hmac_md5(key, data)); } 28 | 29 | /* 30 | * Perform a simple self-test to see if the VM is working 31 | */ 32 | function md5_vm_test() 33 | { 34 | return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72"; 35 | } 36 | 37 | /* 38 | * Calculate the MD5 of an array of little-endian words, and a bit length 39 | */ 40 | function core_md5(x, len) 41 | { 42 | /* append padding */ 43 | x[len >> 5] |= 0x80 << ((len) % 32); 44 | x[(((len + 64) >>> 9) << 4) + 14] = len; 45 | 46 | var a = 1732584193; 47 | var b = -271733879; 48 | var c = -1732584194; 49 | var d = 271733878; 50 | 51 | for(var i = 0; i < x.length; i += 16) 52 | { 53 | var olda = a; 54 | var oldb = b; 55 | var oldc = c; 56 | var oldd = d; 57 | 58 | a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936); 59 | d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586); 60 | c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819); 61 | b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330); 62 | a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897); 63 | d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426); 64 | c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341); 65 | b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983); 66 | a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416); 67 | d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417); 68 | c = md5_ff(c, d, a, b, x[i+10], 17, -42063); 69 | b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162); 70 | a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682); 71 | d = md5_ff(d, a, b, c, x[i+13], 12, -40341101); 72 | c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290); 73 | b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329); 74 | 75 | a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510); 76 | d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632); 77 | c = md5_gg(c, d, a, b, x[i+11], 14, 643717713); 78 | b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302); 79 | a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691); 80 | d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083); 81 | c = md5_gg(c, d, a, b, x[i+15], 14, -660478335); 82 | b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848); 83 | a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438); 84 | d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690); 85 | c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961); 86 | b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501); 87 | a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467); 88 | d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784); 89 | c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473); 90 | b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734); 91 | 92 | a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558); 93 | d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463); 94 | c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562); 95 | b = md5_hh(b, c, d, a, x[i+14], 23, -35309556); 96 | a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060); 97 | d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353); 98 | c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632); 99 | b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640); 100 | a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174); 101 | d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222); 102 | c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979); 103 | b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189); 104 | a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487); 105 | d = md5_hh(d, a, b, c, x[i+12], 11, -421815835); 106 | c = md5_hh(c, d, a, b, x[i+15], 16, 530742520); 107 | b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651); 108 | 109 | a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844); 110 | d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415); 111 | c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905); 112 | b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055); 113 | a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571); 114 | d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606); 115 | c = md5_ii(c, d, a, b, x[i+10], 15, -1051523); 116 | b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799); 117 | a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359); 118 | d = md5_ii(d, a, b, c, x[i+15], 10, -30611744); 119 | c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380); 120 | b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649); 121 | a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070); 122 | d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379); 123 | c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259); 124 | b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551); 125 | 126 | a = safe_add(a, olda); 127 | b = safe_add(b, oldb); 128 | c = safe_add(c, oldc); 129 | d = safe_add(d, oldd); 130 | } 131 | return Array(a, b, c, d); 132 | 133 | } 134 | 135 | /* 136 | * These functions implement the four basic operations the algorithm uses. 137 | */ 138 | function md5_cmn(q, a, b, x, s, t) 139 | { 140 | return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b); 141 | } 142 | function md5_ff(a, b, c, d, x, s, t) 143 | { 144 | return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t); 145 | } 146 | function md5_gg(a, b, c, d, x, s, t) 147 | { 148 | return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t); 149 | } 150 | function md5_hh(a, b, c, d, x, s, t) 151 | { 152 | return md5_cmn(b ^ c ^ d, a, b, x, s, t); 153 | } 154 | function md5_ii(a, b, c, d, x, s, t) 155 | { 156 | return md5_cmn(c ^ (b | (~d)), a, b, x, s, t); 157 | } 158 | 159 | /* 160 | * Calculate the HMAC-MD5, of a key and some data 161 | */ 162 | function core_hmac_md5(key, data) 163 | { 164 | var bkey = str2binl(key); 165 | if(bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz); 166 | 167 | var ipad = Array(16), opad = Array(16); 168 | for(var i = 0; i < 16; i++) 169 | { 170 | ipad[i] = bkey[i] ^ 0x36363636; 171 | opad[i] = bkey[i] ^ 0x5C5C5C5C; 172 | } 173 | 174 | var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz); 175 | return core_md5(opad.concat(hash), 512 + 128); 176 | } 177 | 178 | /* 179 | * Add integers, wrapping at 2^32. This uses 16-bit operations internally 180 | * to work around bugs in some JS interpreters. 181 | */ 182 | function safe_add(x, y) 183 | { 184 | var lsw = (x & 0xFFFF) + (y & 0xFFFF); 185 | var msw = (x >> 16) + (y >> 16) + (lsw >> 16); 186 | return (msw << 16) | (lsw & 0xFFFF); 187 | } 188 | 189 | /* 190 | * Bitwise rotate a 32-bit number to the left. 191 | */ 192 | function bit_rol(num, cnt) 193 | { 194 | return (num << cnt) | (num >>> (32 - cnt)); 195 | } 196 | 197 | /* 198 | * Convert a string to an array of little-endian words 199 | * If chrsz is ASCII, characters >255 have their hi-byte silently ignored. 200 | */ 201 | function str2binl(str) 202 | { 203 | var bin = Array(); 204 | var mask = (1 << chrsz) - 1; 205 | for(var i = 0; i < str.length * chrsz; i += chrsz) 206 | bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (i%32); 207 | return bin; 208 | } 209 | 210 | /* 211 | * Convert an array of little-endian words to a string 212 | */ 213 | function binl2str(bin) 214 | { 215 | var str = ""; 216 | var mask = (1 << chrsz) - 1; 217 | for(var i = 0; i < bin.length * 32; i += chrsz) 218 | str += String.fromCharCode((bin[i>>5] >>> (i % 32)) & mask); 219 | return str; 220 | } 221 | 222 | /* 223 | * Convert an array of little-endian words to a hex string. 224 | */ 225 | function binl2hex(binarray) 226 | { 227 | var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef"; 228 | var str = ""; 229 | for(var i = 0; i < binarray.length * 4; i++) 230 | { 231 | str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) + 232 | hex_tab.charAt((binarray[i>>2] >> ((i%4)*8 )) & 0xF); 233 | } 234 | return str; 235 | } 236 | 237 | /* 238 | * Convert an array of little-endian words to a base-64 string 239 | */ 240 | function binl2b64(binarray) 241 | { 242 | var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 243 | var str = ""; 244 | for(var i = 0; i < binarray.length * 4; i += 3) 245 | { 246 | var triplet = (((binarray[i >> 2] >> 8 * ( i %4)) & 0xFF) << 16) 247 | | (((binarray[i+1 >> 2] >> 8 * ((i+1)%4)) & 0xFF) << 8 ) 248 | | ((binarray[i+2 >> 2] >> 8 * ((i+2)%4)) & 0xFF); 249 | for(var j = 0; j < 4; j++) 250 | { 251 | if(i * 8 + j * 6 > binarray.length * 32) str += b64pad; 252 | else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F); 253 | } 254 | } 255 | return str; 256 | } 257 | -------------------------------------------------------------------------------- /test/webapp/js/sha1.js: -------------------------------------------------------------------------------- 1 | /* 2 | * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined 3 | * in FIPS PUB 180-1 4 | * Version 2.1-BETA Copyright Paul Johnston 2000 - 2002. 5 | * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet 6 | * Distributed under the BSD License 7 | * See http://pajhome.org.uk/crypt/md5 for details. 8 | */ 9 | /* 10 | * Configurable variables. You may need to tweak these to be compatible with 11 | * the server-side, but the defaults work in most cases. 12 | */ 13 | var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */ 14 | var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */ 15 | var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */ 16 | 17 | /* 18 | * These are the functions you'll usually want to call 19 | * They take string arguments and return either hex or base-64 encoded strings 20 | */ 21 | function hex_sha1(s) { 22 | return binb2hex(core_sha1(str2binb(s), s.length * chrsz)); 23 | } 24 | 25 | function b64_sha1(s) { 26 | return binb2b64(core_sha1(str2binb(s), s.length * chrsz)); 27 | } 28 | 29 | function str_sha1(s) { 30 | return binb2str(core_sha1(str2binb(s), s.length * chrsz)); 31 | } 32 | 33 | function hex_hmac_sha1(key, data) { 34 | return binb2hex(core_hmac_sha1(key, data)); 35 | } 36 | 37 | function b64_hmac_sha1(key, data) { 38 | return binb2b64(core_hmac_sha1(key, data)); 39 | } 40 | 41 | function str_hmac_sha1(key, data) { 42 | return binb2str(core_hmac_sha1(key, data)); 43 | } 44 | 45 | /* 46 | * Perform a simple self-test to see if the VM is working 47 | */ 48 | function sha1_vm_test() { 49 | return hex_sha1("abc") == "a9993e364706816aba3e25717850c26c9cd0d89d"; 50 | } 51 | 52 | /* 53 | * Calculate the SHA-1 of an array of big-endian words, and a bit length 54 | */ 55 | function core_sha1(x, len) { 56 | /* append padding */ 57 | x[len >> 5] |= 0x80 << (24 - len % 32); 58 | x[((len + 64 >> 9) << 4) + 15] = len; 59 | 60 | var w = Array(80); 61 | var a = 1732584193; 62 | var b = -271733879; 63 | var c = -1732584194; 64 | var d = 271733878; 65 | var e = -1009589776; 66 | 67 | for (var i = 0; i < x.length; i += 16) { 68 | var olda = a; 69 | var oldb = b; 70 | var oldc = c; 71 | var oldd = d; 72 | var olde = e; 73 | 74 | for (var j = 0; j < 80; j++) { 75 | if (j < 16) w[j] = x[i + j]; 76 | else w[j] = rol(w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16], 1); 77 | var t = safe_add(safe_add(rol(a, 5), sha1_ft(j, b, c, d)), safe_add(safe_add(e, w[j]), sha1_kt(j))); 78 | e = d; 79 | d = c; 80 | c = rol(b, 30); 81 | b = a; 82 | a = t; 83 | } 84 | 85 | a = safe_add(a, olda); 86 | b = safe_add(b, oldb); 87 | c = safe_add(c, oldc); 88 | d = safe_add(d, oldd); 89 | e = safe_add(e, olde); 90 | } 91 | return Array(a, b, c, d, e); 92 | 93 | } 94 | 95 | /* 96 | * Perform the appropriate triplet combination function for the current 97 | * iteration 98 | */ 99 | function sha1_ft(t, b, c, d) { 100 | if (t < 20) return (b & c) | ((~b) & d); 101 | if (t < 40) return b ^ c ^ d; 102 | if (t < 60) return (b & c) | (b & d) | (c & d); 103 | return b ^ c ^ d; 104 | } 105 | 106 | /* 107 | * Determine the appropriate additive constant for the current iteration 108 | */ 109 | function sha1_kt(t) { 110 | return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 : (t < 60) ? -1894007588 : -899497514; 111 | } 112 | 113 | /* 114 | * Calculate the HMAC-SHA1 of a key and some data 115 | */ 116 | function core_hmac_sha1(key, data) { 117 | var bkey = str2binb(key); 118 | if (bkey.length > 16) bkey = core_sha1(bkey, key.length * chrsz); 119 | 120 | var ipad = Array(16), 121 | opad = Array(16); 122 | for (var i = 0; i < 16; i++) { 123 | ipad[i] = bkey[i] ^ 0x36363636; 124 | opad[i] = bkey[i] ^ 0x5C5C5C5C; 125 | } 126 | 127 | var hash = core_sha1(ipad.concat(str2binb(data)), 512 + data.length * chrsz); 128 | return core_sha1(opad.concat(hash), 512 + 160); 129 | } 130 | 131 | /* 132 | * Add integers, wrapping at 2^32. This uses 16-bit operations internally 133 | * to work around bugs in some JS interpreters. 134 | */ 135 | function safe_add(x, y) { 136 | var lsw = (x & 0xFFFF) + (y & 0xFFFF); 137 | var msw = (x >> 16) + (y >> 16) + (lsw >> 16); 138 | return (msw << 16) | (lsw & 0xFFFF); 139 | } 140 | 141 | /* 142 | * Bitwise rotate a 32-bit number to the left. 143 | */ 144 | function rol(num, cnt) { 145 | return (num << cnt) | (num >>> (32 - cnt)); 146 | } 147 | 148 | /* 149 | * Convert an 8-bit or 16-bit string to an array of big-endian words 150 | * In 8-bit function, characters >255 have their hi-byte silently ignored. 151 | */ 152 | function str2binb(str) { 153 | var bin = Array(); 154 | var mask = (1 << chrsz) - 1; 155 | for (var i = 0; i < str.length * chrsz; i += chrsz) 156 | bin[i >> 5] |= (str.charCodeAt(i / chrsz) & mask) << (24 - i % 32); 157 | return bin; 158 | } 159 | 160 | /* 161 | * Convert an array of big-endian words to a string 162 | */ 163 | function binb2str(bin) { 164 | var str = ""; 165 | var mask = (1 << chrsz) - 1; 166 | for (var i = 0; i < bin.length * 32; i += chrsz) 167 | str += String.fromCharCode((bin[i >> 5] >>> (24 - i % 32)) & mask); 168 | return str; 169 | } 170 | 171 | /* 172 | * Convert an array of big-endian words to a hex string. 173 | */ 174 | function binb2hex(binarray) { 175 | var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef"; 176 | var str = ""; 177 | for (var i = 0; i < binarray.length * 4; i++) { 178 | str += hex_tab.charAt((binarray[i >> 2] >> ((3 - i % 4) * 8 + 4)) & 0xF) + hex_tab.charAt((binarray[i >> 2] >> ((3 - i % 4) * 8)) & 0xF); 179 | } 180 | return str; 181 | } 182 | 183 | /* 184 | * Convert an array of big-endian words to a base-64 string 185 | */ 186 | function binb2b64(binarray) { 187 | var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 188 | var str = ""; 189 | for (var i = 0; i < binarray.length * 4; i += 3) { 190 | var triplet = (((binarray[i >> 2] >> 8 * (3 - i % 4)) & 0xFF) << 16) | (((binarray[i + 1 >> 2] >> 8 * (3 - (i + 1) % 4)) & 0xFF) << 8) | ((binarray[i + 2 >> 2] >> 8 * (3 - (i + 2) % 4)) & 0xFF); 191 | for (var j = 0; j < 4; j++) { 192 | if (i * 8 + j * 6 > binarray.length * 32) str += b64pad; 193 | else str += tab.charAt((triplet >> 6 * (3 - j)) & 0x3F); 194 | } 195 | } 196 | return str; 197 | } -------------------------------------------------------------------------------- /test/webapp/key/rsa_private_key.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIICXAIBAAKBgQC0Llg1bVZhnyslfezwfeOkvnXWq59bDtmQyHvxkP/38Fw8QQXB 3 | fROCgzGc+Te6pOPl6Ye+vQ1rAnisBaP3rMk40i3OpallzVkuwRKydek3V9ufPpZE 4 | EH4eBgInMSDiMsggTWxcI/Lvag6eHjkSc67RTrj96oxj0ipVRqjxW4X6HQIDAQAB 5 | AoGAEE2pOZxdFpQ6aTgNum0Jrhx1uSjqUGj1kr4xSNhf8OVU0zbm+G0C2OpaEOQU 6 | ANVusZ0B5WZh0m700EvqXDzMMCsa9QhKPP4z9Nd09RHdcQtysbSXnWc2VKDYxiqy 7 | bIsnnlHRemCqHzQVqLaoKa0OVGFouunSqKFiVbXZ9bb/aMECQQDhYD97TI5CpHxU 8 | 7tW67uphUD4xoND3v5ENE//9mgjjJsxnNarpYQDcZgPN2DNMSVmBzuItiiTBuLBE 9 | uXDSBoGFAkEAzKn7H7Aa9G6hLfvHBfxVYtOuybqQwxsdXpQ6kH14dH2a+2A2tIw9 10 | M2U4/pNz89nLC0pzWaYwCgNXHsmeBjYtuQJAYxT5U6+Ya1v8/Sny9LfMevPYI+Fb 11 | fU/O6Tz9sfRiK9sGyekiNm/a/Qosafa+tq8YlqTpcrPk7PXRKKWOIAeUMQJAZDqO 12 | eBtHaBNRrfJSqnTD4C0ouTQ7tsDtpibTc3Vu6yWkI50fzVWslyHoQow1yeMME9B3 13 | Ix1HA3BVVweH8yTPSQJBAKY6NQgHEonErU0k7KzYQFncUAwp3k/TztZYVe86WNjk 14 | 3Ans1T2Dexf5w8pu0TStXxrBNI0MjP9OstFUSR8v92o= 15 | -----END RSA PRIVATE KEY----- 16 | -------------------------------------------------------------------------------- /test/webapp/key/rsa_public_key.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PUBLIC KEY----- 2 | MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC0Llg1bVZhnyslfezwfeOkvnXW 3 | q59bDtmQyHvxkP/38Fw8QQXBfROCgzGc+Te6pOPl6Ye+vQ1rAnisBaP3rMk40i3O 4 | pallzVkuwRKydek3V9ufPpZEEH4eBgInMSDiMsggTWxcI/Lvag6eHjkSc67RTrj9 5 | 6oxj0ipVRqjxW4X6HQIDAQAB 6 | -----END PUBLIC KEY----- 7 | -------------------------------------------------------------------------------- /test/webapp/login_check.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/webapp/rsa.php: -------------------------------------------------------------------------------- 1 |