How can I hash a password in Java?

You can actually use a facility built in to the Java runtime to do this. The SunJCE in Java 6 supports PBKDF2, which is a good algorithm to use for password hashing. byte[] salt = new byte[16]; random.nextBytes(salt); KeySpec spec = new PBEKeySpec(“password”.toCharArray(), salt, 65536, 128); SecretKeyFactory f = SecretKeyFactory.getInstance(“PBKDF2WithHmacSHA1”); byte[] hash = f.generateSecret(spec).getEncoded(); Base64.Encoder … Read more

How to hash some string with sha256 in Java?

SHA-256 isn’t an “encoding” – it’s a one-way hash. You’d basically convert the string into bytes (e.g. using text.getBytes(StandardCharsets.UTF_8)) and then hash the bytes. Note that the result of the hash would also be arbitrary binary data, and if you want to represent that in a string, you should use base64 or hex… don’t try … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)