Salve,
Ho un problema con un applet e js, uso netbeans e glassfish, quando faccio l'applet in locale funziona tutto, invece se faccio connettere un altro pc non funziona e mi da questo errore [Error] Error: Error calling method on NPObject.
encrypt (admin.html, line 53)
non risco a capire quel'e' il problema; Utilizzo i websocket infatti la connessione funziona ma non va l'applet, pero non mi torna che funziona localmenteche sbaglio?
Grazie
codice HTML:<script language="Javascript"> function accessAppletMethod() { var t = "dati"; var risp = document.Applet.encrypt(t); webSocket.send(risp); } var webSocket; var messages = document.getElementById("messages"); var risultato = ""; function openSocket() { // Ensures only one connection is open at a time if (webSocket !== undefined && webSocket.readyState !== WebSocket.CLOSED) { writeResponse("WebSocket is already opened."); return; } // Create a new instance of the websocket webSocket = new WebSocket("ws://pingamitutto.ddns.net:8080/bechini/socketadmin"); /** * Binds functions to the listeners for the websocket. */ webSocket.onopen = function (event) { // For reasons I can't determine, onopen gets called twice // and the first time event.data is undefined. // Leave a comment if you know the answer. if (event.data === undefined) return; writeResponse(event.data); }; webSocket.onmessage = function (event) { var risp = document.Applet.encrypt(event.data.toString());//problema webSocket.send(risultato); alert("un lavoro completato");//here the string have the correct length }; webSocket.onclose = function (event) { writeResponse("Connection closed"); }; } /** * Sends the value of the text input to the server */ </script> <head> <title>TODO supply a title</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body onload="openSocket();"> <div id="messages"> <p> sei connesso al server a breve ti arriva materiale da elaborare</p> </div> <!-- C:\Users\lorenzo §\Documents\NetBeansProjects\bechini\build\web\WEB-INF\classes --> <!--a href="../build/web/WEB-INF/classes/App.class"></a--> <applet width="300" height="100" top="400" id="Applet" code="App.class"> </applet> <div id="messages"></div> </body>
questa e' l'applet
import java.applet.Applet;
import org.apache.commons.codec.binary.Base64;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import javax.crypto.*;
import javax.crypto.spec.SecretKeySpec;
import javax.swing.JOptionPane;
import netscape.javascript.JSObject;
public class App extends Applet {
public boolean encrypt(String messaggio) {
JSObject window = JSObject.getWindow(this);
String pass = messaggio.substring(0, 16);
String file = messaggio.substring(16);
byte[] byteDataToEncrypt = Base64.decodeBase64(file);
byte[] byteCipherText = null;
byte[] key = stringToByte(pass); //new byte[128/8]; ERRORE
try {
Cipher aesCipher = Cipher.getInstance("AES");//DICE INVALIDA KEY
aesCipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key, "AES"), aesCipher.getParameters());//DICE INVALIDA KEY
byteCipherText = aesCipher.doFinal(byteDataToEncrypt);
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException e) {
JOptionPane.showMessageDialog(null, "ECC " + e);
}
messaggio = Base64.encodeBase64URLSafeString(byteCipherText);
window.setMember("risultato", messaggio.substring(0, messaggio.length() / 2));
return true;
}
public static byte[] stringToByte(String s) {
byte[] b = new byte[s.length()];
for (int i = 0; i < s.length(); i++) {
b[i] = (byte) s.charAt(i);
}
return b;
}
public static String byteToString(byte[] b, int size) {
char[] c = new char[size];
for (int i = 0; i < size; i++) {
c[i] = (char) b[i];
}
return new String(c);
}
}

che sbaglio?
Rispondi quotando
