Skip to content

Instantly share code, notes, and snippets.

@nitincoded
Created November 27, 2016 12:44
Show Gist options
  • Save nitincoded/6b4191a7b9f5cd49c13267e66bfb54da to your computer and use it in GitHub Desktop.
Save nitincoded/6b4191a7b9f5cd49c13267e66bfb54da to your computer and use it in GitHub Desktop.
com.nitin.EamPwHasher
package com.nitin;
import java.security.MessageDigest;
import org.apache.commons.codec.binary.Base64;
public class EamPwHasher {
public static String hashedPassword(String aUsername, String aPassword) throws Exception {
MessageDigest hasher = MessageDigest.getInstance("SHA-256");
byte[] salt = (aUsername.toUpperCase()+"@#$ABCDEFGHIJKLMNOPQRSTUVWXYZ/(-").substring(0, 32).getBytes("UTF-8");
hasher.update(salt);
return "{S2X}" + Base64.encodeBase64String(hasher.digest(aPassword.toUpperCase().getBytes("UTF-8")));
}
}
@nitincoded
Copy link
Author

Drop the toUpperCase if you change the config settings to make the password case sensitive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment