Archiv verlassen und diese Seite im Standarddesign anzeigen : Fehlermeldung, welches mir nichts sagt
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /index2.jsp at line 69
66: decrypted.append(new String(decryptedBytes, ENCODING));
67: }
68: } catch (Exception e) {
69: throw new RuntimeException("Couldn't decrypt value", e);
70: }
71: return decrypted.toString();
72: }
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:524)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:435)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.14 logs.
Kan mir jemand helfen bzw. einen Tipp geben? Ich hab einiges versucht, aber leider erfolgslos.
Danke
blackdrag0n
26.11.2008, 19:20
throw new RuntimeException("Couldn't decrypt value", e);
durch
e.printStackTrace();
ersetzen.
is zwar nich 100% dasselbe aber sollte dann funktionieren.
des weiteren frag ich mich was sowas wie
return decrypted.toString();
in JSP seiten zu suchen hat oO
hallo blackdrag0n,
vielen Dank für deine Antwort. Die Fehlermeldung ist nun weg. Aber ich erhalte keinen sehenswerten Rückgabewert der Funktion, wenn ich sie aufrufe. Nur eine weisse Website.
Der gesamte Code sieht wie folgt aus:
<%@page import="java.io.BufferedInputStream"%>
<%@page import="java.io.IOException"%>
<%@page import="java.io.InputStream"%>
<%@page import="java.security.Key"%>
<%@page import="java.security.KeyFactory"%>
<%@page import="java.security.NoSuchAlgorithmException"%>
<%@page import="java.security.interfaces.RSAPrivateKey"%>
<%@page import="java.security.spec.InvalidKeySpecException"%>
<%@page import="java.security.spec.PKCS8EncodedKeySpec"%>
<%@page import="javax.crypto.Cipher"%>
<%@page import="java.lang.reflect.Array"%>
<%@page import="java.util.*"%>
<%@page import="sun.misc.BASE64Decoder"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<% String encryptedText = request.getParameter("encrypted"); %>
<%!
/**
* Constant for the algorithm
*/
final String ALGORITHM = "RSA";
/**
* Constant for the transformation
*/
final String TRANSFORMATION = "RSA/ECB/PKCS1PADDING";
/**
* Constant for the character encoding.
*/
final String ENCODING = "UTF-8";
/**
* base64 decoder
*/
Key privateKey;
final BASE64Decoder BASE64DECODER = new BASE64Decoder();
/**
* name of the local public key file
*/
final String PRIVATE_KEY_NAME = "private_key.der";
/**
* private key for the decryption
*/
/**
* return a decrypted value with the available key
*
* @param encrypted the encrypted value
* @param keypath path to the key
* @return the decrypted value
*/
String decrypt(String encrypted) {
StringBuffer decrypted = new StringBuffer();
try {
Cipher cipher = Cipher.getInstance(TRANSFORMATION);
cipher.init(Cipher.DECRYPT_MODE, getPrivateKey());
byte[] encoded = BASE64DECODER.decodeBuffer(encrypted);
for (int i = 0; i < encoded.length; i += getBlockSize()) {
byte[] tmp = subarray(encoded, i, i + getBlockSize());
byte[] decryptedBytes = cipher.doFinal(tmp);
decrypted.append(new String(decryptedBytes, ENCODING));
}
} catch (Exception e) {
e.printStackTrace();
}
return decrypted.toString();
}
byte[] subarray(byte[] array, int startIndexInclusive, int endIndexExclusive) {
if (array == null) {
return null;
}
if (startIndexInclusive < 0) {
startIndexInclusive = 0;
}
if (endIndexExclusive > array.length) {
endIndexExclusive = array.length;
}
int newSize = endIndexExclusive - startIndexInclusive;
Class type = array.getClass().getComponentType();
if (newSize <= 0) {
return (byte[]) Array.newInstance(type, 0);
}
byte[] subarray = (byte[]) Array.newInstance(type, newSize);
System.arraycopy(array, startIndexInclusive, subarray, 0, newSize);
return subarray;
}
Key loadPrivateKey() throws InvalidKeySpecException,
NoSuchAlgorithmException, IOException {
Key key = null;
if (key == null) {
InputStream inputStream = ClassLoader.getSystemResourceAsStream(PRIVATE_KEY_NAME);
byte[] raw = getBytes(inputStream);
PKCS8EncodedKeySpec tSpec = new PKCS8EncodedKeySpec(raw);
key = KeyFactory.getInstance(ALGORITHM).generatePrivate(tSpec);
}
return key;
}
byte[] getBytes(InputStream pInput) throws IOException {
BufferedInputStream bos = null;
try {
bos = new BufferedInputStream(pInput);
byte[] bytes = new byte[bos.available()];
bos.read(bytes);
return bytes;
} finally {
if (bos != null) {
bos.close();
}
}
}
Key getPrivateKey() throws InvalidKeySpecException, NoSuchAlgorithmException, IOException {
if (privateKey == null) {
privateKey = loadPrivateKey();
}
return privateKey;
}
private int getBlockSize() throws InvalidKeySpecException,
NoSuchAlgorithmException, IOException {
RSAPrivateKey key = (RSAPrivateKey) getPrivateKey();
return key.getModulus().bitLength() / 8;
}
%>
<% out.print(decrypt(encryptedText)); %>
blackdrag0n
28.11.2008, 09:22
nunja... meine erste frage wäre:
was zum geier hat das in einer JSP-Seite zu suchen?
weil das was du da machst gehört mit sicherheit NICHT in eine JSP-Seite...
Hi,
also mich würde mal interessieren, warum das ein Problem ist. Wenn er etwas entschlüsseln will, muss er den Code dafür auch irgendwo stehen haben ;)
cihan_g: Ich bin zwar kein Java-Experte, aber ich vermute, dass du nun nichts siehst, weil der Fehler ja immer noch auftritt, aber die Ausgabe der Exception einfach nicht mehr auf der Seite landet. e.printStackTrace() schreibt ja in den error stream, und der wird wohl nicht ausgegeben. e.printStackTrace(System.out) oder e.printStackTrace(out) oder so ähnlich sollten dir eine bessere Meldung geben. Alternativ könntest du (testweise) die Exception auch einfach mal nicht fangen (bzw. fangen und mit throw e; gleich wieder werfen), und dann bekommste die richtige Meldung auch so schön wie oben angezeigt.
blackdrag0n
30.11.2008, 23:11
also ich würd ja sowas in ne Java-Klasse schreiben und nich in ne JSP seite...
naja... muss jeder selbst wissen :X
System.out.println(e.printStackTrace());
schiebt dir die exception in den stream (wenn du mit eclipse gestartet hast findest das ganze dann in der "Log-Console" von eclipse. wenn du den tomcat gestartet hast gibts das ganze im tomcat verzeichnis unter logs/catalina.out)
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.