Note that there are some explanatory texts on larger screens.

plurals
  1. POTomcat decrypt aes different from Java Main application
    primarykey
    data
    text
    <p>I have an AES encrypted byte array. When I decrypt this array in java application, everything is fine. But in a servlet container, decrypted wrong. </p> <p>Here ise my byte array </p> <pre><code> String [] str = new String[] {"41", "23", "67" ,"-124", "-56" ,"-35" ,"89", "-54" ,"-17" ,"-49" ,"-53", "-21" ,"125" ,"4", "98", "-13", "60" ,"-72", "12", "75" ,"-105" ,"-104", "107", "34", "1", "-109", "-19", "-102", "-72", "9" ,"26" ,"-39", "-60", "-15", "0" ,"112", "-5", "-86", "-7", "5" ,"75", "100" ,"94", "-47", "6", "-81", "-22", "82", "97" ,"114", "3", "-24", "-80", "67", "106", "-100" ,"-35", "-83", "54", "-95", "124", "-22", "-100", "-47" }; byte [] inv = new byte[str.length]; int count = 0; for (String s : str) { inv[count++] = Byte.valueOf(s); } </code></pre> <p>The result of Java Application </p> <pre><code>Decrypted: 000000.016*kWh|000000.007*kWh|000000.015*kWh|000000.000*kWh </code></pre> <p>My application code </p> <pre><code> byte[] keyBytes = "vikoAmrPass12345".getBytes(); SecretKeySpec key = new SecretKeySpec(keyBytes, "AES"); Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding"); cipher.init(Cipher.DECRYPT_MODE, key); byte [] out = cipher.doFinal(inv); System.out.println("Decrypted: " +new String(out)); </code></pre> <p>My web code which is works on servlet container is definitly same with above one. But the container decypted result is </p> <pre><code>'?f ??0??????b]5hJ?F*`U????.8??p@?]?u?~Nb??z?????{3??;? </code></pre> <p>What is wrong here ? </p> <p>In my application, I got encrypted byte array as </p> <pre><code>ServerSocket ss = new ServetSocket(port); Socket socket = ss.accept(); InputStream in = socket.getInputStream(); byte [] sizeBuffer = new byte[5]; in.read(sizeBuffer); byte [] dataBuffer = new byte[Integer.valueOf(""+new String(sizeBuffer)]; in.read(dataBuffer); </code></pre> <p>Encrypted data exists on <em>dataBuffer</em> array. And encryption handled in an embedded device.</p> <p>My configuration </p> <p>java 1.6 tomcat 7.1</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload