my code is as below while running it i got the error as shown,
// TODO Auto-generated method stub
String user = request.getParameter("user");
HttpSession session = request.getSession();
CryptoEngine inCipher = (CryptoEngine) session
.getAttribute("inCipher");
CryptoEngine outCipher = (CryptoEngine) session
.getAttribute("outCipher");
// If the ciphers aren't found, create and initialize a new pair.
if (inCipher == null && outCipher == null) {
// Retrieve the client's keys.
byte[] inKey = getInKey(user);
byte[] outKey = getOutKey(user);
// Create and initialize the ciphers.
inCipher = new CryptoEngine();
outCipher = new CryptoEngine();
session.setAttribute("inCipher", inCipher);
session.setAttribute("outCipher", outCipher);
System.out.println("1");
}
System.out.println("2");
// Retrieve the client's message.
String clientHex = request.getParameter("message");
System.out.println(clientHex + " aeskey" + inCipher.getAESkey());
byte[] clientCiphertext = HexCodec.hexToBytes(clientHex);
byte[] clientDecrypted = new byte[clientCiphertext.length];
clientDecrypted = inCipher.AESFastDecrypt(clientCiphertext);
System.out.println("message = " + new String(clientDecrypted));
// Create the response message.
String message = "Hello, this is StealthServlet.";
// Encrypt the message.
byte[] plaintext = message.getBytes();
byte[] ciphertext = new byte[plaintext.length];
// outCipher.processBlock(plaintext, 0, ciphertext, 0);
ciphertext = outCipher.AESFastEncrypt(plaintext);
char[] hexCiphertext = HexCodec.bytesToHex(ciphertext);
response.setContentType("text/plain");
response.setContentLength(hexCiphertext.length);
PrintWriter out = response.getWriter();
out.println(hexCiphertext);
Error:
InvalidCipherTextException: pad block corrupted
00:31:52,227 ERROR [STDERR] at PKCS7Padding.padCount(PKCS7Padding.java:58)
00:31:52,227 ERROR [STDERR] at PaddedBufferedBlockCipher.doFinal(PaddedBufferedBlockCipher.java:278)
00:31:52,227 ERROR [STDERR] at CryptoEngine.AESFastDecrypt(CryptoEngine.java:88)
00:31:52,227 ERROR [STDERR] at CryptoServlet.doGet(CryptoServlet.java:69)
00:31:52,227 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
00:31:52,227 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
00:31:52,227 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
00:31:52,227 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
00:31:52,227 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
00:31:52,227 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
00:31:52,227 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
00:31:52,227 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
00:31:52,227 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
00:31:52,228 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
00:31:52,228 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
00:31:52,228 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
00:31:52,228 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
00:31:52,228 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
00:31:52,228 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
00:31:52,228 ERROR [STDERR] at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
00:31:52,228 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
00:31:52,228 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
00:31:52,228 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
00:31:52,228 ERROR [STDERR] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:601)
00:31:52,228 ERROR [STDERR] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)