cz.mmsparams.api.utils.SimplePasswordUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of MmsParamsAPI Show documentation
Show all versions of MmsParamsAPI Show documentation
Common library for MmsParams system
The newest version!
package cz.mmsparams.api.utils;
import java.util.Base64;
import cz.mmsparams.api.http.auth.JwtRequest;
public class SimplePasswordUtil
{
private static final String SEPARATOR = ":";
public static String encrypt(JwtRequest jwtRequest)
{
if (jwtRequest == null || StringUtil.isEmptyOrNull(jwtRequest.getUsername())
|| StringUtil.isEmptyOrNull(jwtRequest.getPassword()))
return null;
String authString = jwtRequest.getUsername() + SEPARATOR + jwtRequest.getPassword();
return Base64.getEncoder().encodeToString(authString.getBytes());
}
/**
* Decrypt base64 username:password
*
* @param param base64 username:password to decrypt
* @return username-password pair
*/
public static JwtRequest decrypt(String param)
{
if (StringUtil.isEmptyOrNull(param))
{
return new JwtRequest(null, null);
}
String s = new String(Base64.getDecoder().decode(param));
String[] up = s.split(SEPARATOR);
if (up.length == 2)
{
return new JwtRequest(up[0], up[1]);
}
return new JwtRequest(null, null);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy