/* * (non-Javadoc) * * @see org.jboss.security.plugins.JaasSecurityDomainMBean#encode64(byte[]) */ @ManagementOperation( description = "Encode a secret as a base64 string using the cipher algorithm and the KeyStore password", params = {@ManagementParameter(name = "secret", description = "The secret to be encoded")}, impact = Impact.ReadOnly) public String encode64(byte[] secret) throws Exception { byte[] encoding = encode(secret); String b64 = CryptoUtil.tob64(encoding); return b64; }
private User createNewUser(String email, String password) { User user = new User(); user.setEmail(email); user.setPassword( CryptoUtil.createPasswordHash("MD5", CryptoUtil.BASE64_ENCODING, null, null, password)); user.setActive(Boolean.FALSE); user.setToken(generateToken()); return user; }
/* * (non-Javadoc) * * @see org.jboss.security.plugins.JaasSecurityDomainMBean#decode64(java.lang.String) */ @ManagementOperation( description = "Decode a base64 secret using the cipher algorithm and the KeyStore password", params = {@ManagementParameter(name = "secret", description = "The secret to be encoded")}, impact = Impact.ReadOnly) public byte[] decode64(String secret) throws Exception { byte[] encoding = CryptoUtil.fromb64(secret); // JBAS-7094: fix leading zeros if (encoding.length % 8 != 0) { int length = encoding.length; int newLength = ((length / 8) + 1) * 8; int pad = newLength - length; // number of leading zeros byte[] old = encoding; encoding = new byte[newLength]; for (int i = old.length - 1; i >= 0; i--) { encoding[i + pad] = old[i]; } } byte[] decode = decode(encoding); return decode; }