Note that there are some explanatory texts on larger screens.

plurals
  1. POplay framework session returns wrong value with sha256
    primarykey
    data
    text
    <p>I am having a problem with the session in play framework 1.2.4. When I add a SHA256-hash of a particular String ("testDude5") to the session and retrieve it afterwards, the values are not the same. It doesn't happen with other Strings like "testDude1". Here is the sample code to reproduce the result. </p> <pre><code>package controllers; import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import play.mvc.Controller; public class ExampleController extends Controller { public static final String test1 = "testDude1"; public static final String test2 = "testDude5"; public static void set() { session.put("test1", getHash(test1)); session.put("test2", getHash(test2)); } public static void get() { String output = ""; output += "Test 1 compare: "; output += session.get("test1").equals(getHash(test1)) ? "success" : "failed"; output += "\n"; output += "Test 2 compare: "; output += session.get("test2").equals(getHash(test2)) ? "success" : "failed"; output += "\n"; renderText(output); } /** * Generates the hash value for a password. * * @param password * @return hash */ public static String getHash(String password) { // Create an digest object MessageDigest md; try { // Try to get sha-265 md = MessageDigest.getInstance("SHA-256"); // Encrypt the password md.update(password.getBytes("UTF-8")); // Get the encrypted password byte[] digest = md.digest(); // Convert byte array to String String str = new String(digest); // Return encrypted password return str; } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return null; } } </code></pre> <p>I am totally puzzled by this. Does anyone have an idea whats going on there. Thanks for any advice.</p> <p>Cheers</p>
    singulars
    1. This table or related slice is empty.
    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.
    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