本文整理汇总了Java中org.springframework.security.crypto.codec.Base64.decode方法的典型用法代码示例。如果您正苦于以下问题:Java Base64.decode方法的具体用法?Java Base64.decode怎么用?Java Base64.decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.security.crypto.codec.Base64
的用法示例。
在下文中一共展示了Base64.decode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extractAndDecodeHeader
import org.springframework.security.crypto.codec.Base64; //导入方法依赖的package包/类
private String[] extractAndDecodeHeader(String header, HttpServletRequest request) throws IOException {
byte[] base64Token = header.substring(6).getBytes("UTF-8");
byte[] decoded;
try {
decoded = Base64.decode(base64Token);
} catch (IllegalArgumentException var7) {
throw new BadCredentialsException("Failed to decode basic authentication token");
}
String token = new String(decoded, "UTF-8");
int delim = token.indexOf(":");
if (delim == -1) {
throw new BadCredentialsException("Invalid basic authentication token");
} else {
return new String[]{token.substring(0, delim), token.substring(delim + 1)};
}
}
示例2: extractAndDecodeHeader
import org.springframework.security.crypto.codec.Base64; //导入方法依赖的package包/类
/**
* Decodes the header into a username and password.
*
* @throws BadCredentialsException if the Basic header is not present or is not valid
* Base64
*/
private String[] extractAndDecodeHeader(String header, HttpServletRequest request)
throws IOException {
byte[] base64Token = header.substring(6).getBytes("UTF-8");
byte[] decoded;
try {
decoded = Base64.decode(base64Token);
}
catch (IllegalArgumentException e) {
throw new BadCredentialsException(
"Failed to decode basic authentication token");
}
String token = new String(decoded, getCredentialsCharset(request));
int delim = token.indexOf(":");
if (delim == -1) {
throw new BadCredentialsException("Invalid basic authentication token");
}
return new String[] { token.substring(0, delim), token.substring(delim + 1) };
}
示例3: extractCredentials
import org.springframework.security.crypto.codec.Base64; //导入方法依赖的package包/类
@Override
public AuthenticationRequest extractCredentials(HttpServletRequest request) {
// Only support Kerberos authentication when running securely
if (!request.isSecure()) {
return null;
}
String headerValue = request.getHeader(AUTHORIZATION);
if (!isValidKerberosHeader(headerValue)) {
return null;
}
logger.debug("Detected 'Authorization: Negotiate header in request {}", request.getRequestURL());
byte[] base64Token = headerValue.substring(headerValue.indexOf(" ") + 1).getBytes(StandardCharsets.UTF_8);
byte[] kerberosTicket = Base64.decode(base64Token);
if (kerberosTicket != null) {
logger.debug("Successfully decoded SPNEGO/Kerberos ticket passed in Authorization: Negotiate <ticket> header.", request.getRequestURL());
}
return new AuthenticationRequest(null, kerberosTicket, authenticationDetailsSource.buildDetails(request));
}
示例4: extractAndDecodeHeader
import org.springframework.security.crypto.codec.Base64; //导入方法依赖的package包/类
private String[] extractAndDecodeHeader(String header) throws IOException {
byte[] base64Token = header.substring(6).getBytes("UTF-8");
byte[] decoded;
try {
decoded = Base64.decode(base64Token);
} catch (IllegalArgumentException e) {
throw new BadCredentialsException("Failed to decode basic authentication token");
}
String token = new String(decoded, "UTF-8");
int delim = token.indexOf(":");
if (delim == -1) {
throw new BadCredentialsException("Invalid basic authentication token");
}
return new String[] {token.substring(0, delim), token.substring(delim + 1)};
}
开发者ID:gravitee-io,项目名称:graviteeio-access-management,代码行数:20,代码来源:ClientAwareAuthenticationDetailsSource.java
示例5: extractAndDecodeHeader
import org.springframework.security.crypto.codec.Base64; //导入方法依赖的package包/类
private String[] extractAndDecodeHeader(String header, HttpServletRequest request)
throws IOException {
byte[] base64Token = header.substring(6).getBytes("UTF-8");
byte[] decoded;
try {
decoded = Base64.decode(base64Token);
}
catch (IllegalArgumentException e) {
throw new BadCredentialsException(
"Failed to decode basic authentication token");
}
String token = new String(decoded, getCredentialsCharset(request));
int delim = token.indexOf(":");
if (delim == -1) {
throw new BadCredentialsException("Invalid basic authentication token");
}
return new String[] { token.substring(0, delim), token.substring(delim + 1) };
}
示例6: Desencriptar
import org.springframework.security.crypto.codec.Base64; //导入方法依赖的package包/类
public static String Desencriptar(String textoEncriptado) throws Exception {
String base64EncryptedString = "";
try {
byte[] message = Base64.decode(textoEncriptado.getBytes("utf-8"));
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] digestOfPassword = md.digest(secretKey.getBytes("utf-8"));
byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24);
SecretKey key = new SecretKeySpec(keyBytes, "DESede");
Cipher decipher = Cipher.getInstance("DESede");
decipher.init(Cipher.DECRYPT_MODE, key);
byte[] plainText = decipher.doFinal(message);
base64EncryptedString = new String(plainText, "UTF-8");
} catch (Exception ex) {
}
return base64EncryptedString;
}
示例7: extractAndDecodeHeader
import org.springframework.security.crypto.codec.Base64; //导入方法依赖的package包/类
/**
* Decodes the header into a username and password.
*
* @throws org.springframework.security.authentication.BadCredentialsException if the Basic header is not present or is not valid Base64
*/
private String[] extractAndDecodeHeader(String header, HttpServletRequest request) throws IOException {
byte[] base64Token = header.substring(6).getBytes("UTF-8");
byte[] decoded;
try {
decoded = Base64.decode(base64Token);
} catch (IllegalArgumentException e) {
throw new BadCredentialsException("Failed to decode basic authentication token");
}
String token = new String(decoded, getCredentialsCharset(request));
int delim = token.indexOf(":");
if (delim == -1) {
throw new BadCredentialsException("Invalid basic authentication token");
}
return new String[] {token.substring(0, delim), token.substring(delim + 1)};
}
示例8: extractAndDecodeHeader
import org.springframework.security.crypto.codec.Base64; //导入方法依赖的package包/类
/**
* Decodes the header into a username and password.
*
* @throws BadCredentialsException
* if the Basic header is not present or is not valid Base64
*/
private String[] extractAndDecodeHeader(String header, HttpServletRequest request) {
try {
byte[] base64Token = header.substring(AUTHORIZATION_PREFIX.length()).getBytes("UTF-8");
byte[] decoded;
try {
decoded = Base64.decode(base64Token);
} catch (IllegalArgumentException e) {
throw new BadCredentialsException("Failed to decode basic authentication token");
}
String token = new String(decoded, getCredentialsCharset(request));
int delim = token.indexOf(":");
if (delim == -1) {
throw new BadCredentialsException("Invalid basic authentication token");
}
return new String[] { token.substring(0, delim), token.substring(delim + 1) };
} catch (IOException ioe) {
throw new RuntimeException("Failed to decode auth tokens");
}
}
示例9: extractAndDecodeHeader
import org.springframework.security.crypto.codec.Base64; //导入方法依赖的package包/类
/**
* Decodes the header into a username and password.
*
* @throws BadCredentialsException if the Basic header is not present or is not valid Base64
*/
private String[] extractAndDecodeHeader(String header) throws IOException {
byte[] base64Token = header.substring(6).getBytes(CREDENTIALS_CHARSET);
byte[] decoded;
try {
decoded = Base64.decode(base64Token);
} catch (IllegalArgumentException e) {
throw new BadCredentialsException("Failed to decode basic authentication token");
}
String token = new String(decoded, CREDENTIALS_CHARSET);
int delim = token.indexOf(":");
if (delim == -1) {
throw new BadCredentialsException("Invalid basic authentication token");
}
return new String[] {token.substring(0, delim), token.substring(delim + 1)};
}
示例10: obtainUserAndPasswordFromBasicAuthenticationHeader
import org.springframework.security.crypto.codec.Base64; //导入方法依赖的package包/类
private String[] obtainUserAndPasswordFromBasicAuthenticationHeader(HttpServletRequest httpServletRequest) throws Exception{
// Authorization header
String authHeader = httpServletRequest.getHeader("Authorization");
if (authHeader == null) {
throw new BadCredentialsException("Authorization header not found");
}
// Decode the authorization string
String token;
try{
//Excluded "Basic " initial string
byte[] decoded = Base64.decode(authHeader.substring(6).getBytes());
token = new String(decoded);
} catch (IllegalArgumentException e) {
throw new BadCredentialsException("Failed to decode basic authentication token");
}
int separator = token.indexOf(":");
if (separator == -1) {
throw new BadCredentialsException("Invalid basic authentication token");
}
return new String[] {token.substring(0, separator), token.substring(separator + 1)};
}
示例11: checkBasicAuthorization
import org.springframework.security.crypto.codec.Base64; //导入方法依赖的package包/类
private void checkBasicAuthorization(String authorization, HttpServletResponse httpResponse) throws IOException {
StringTokenizer tokenizer = new StringTokenizer(authorization);
if (tokenizer.countTokens() < 2) {
return;
}
if (!tokenizer.nextToken().equalsIgnoreCase("Basic")) {
return;
}
String base64 = tokenizer.nextToken();
String loginPassword = new String(Base64.decode(base64.getBytes(StandardCharsets.UTF_8)));
System.out.println("loginPassword = " + loginPassword);
tokenizer = new StringTokenizer(loginPassword, ":");
System.out.println("tokenizer = " + tokenizer);
checkUsernameAndPassword(tokenizer.nextToken(), tokenizer.nextToken(), httpResponse);
}
示例12: extractAndDecodeHeader
import org.springframework.security.crypto.codec.Base64; //导入方法依赖的package包/类
private String[] extractAndDecodeHeader(String header) throws IOException
{
if (header == null || header.isEmpty ())
{
return null;
}
byte[] base64Token = header.substring(6).getBytes("UTF-8");
byte[] decoded;
try
{
decoded = Base64.decode(base64Token);
}
catch (IllegalArgumentException e)
{
throw new BadCredentialsException(
"Failed to decode basic authentication token.");
}
String token = new String(decoded, "UTF-8");
int delim = token.indexOf(":");
if (delim == -1)
{
throw new BadCredentialsException(
"Invalid basic authentication token.");
}
return new String[]{token.substring(0,delim),token.substring(delim+1)};
}
示例13: extractAndDecodeHeader
import org.springframework.security.crypto.codec.Base64; //导入方法依赖的package包/类
private String[] extractAndDecodeHeader(String header) throws IOException
{
if (header == null || header.isEmpty())
{
return null;
}
byte[] base64Token = header.substring(6).getBytes("UTF-8");
byte[] decoded;
try
{
decoded = Base64.decode(base64Token);
}
catch (IllegalArgumentException e)
{
throw new BadCredentialsException("Failed to decode basic authentication token.");
}
String token = new String(decoded, "UTF-8");
int delim = token.indexOf(":");
if (delim == -1)
{
throw new BadCredentialsException("Invalid basic authentication token.");
}
return new String[]
{
token.substring(0, delim), token.substring(delim + 1)
};
}
示例14: fromString
import org.springframework.security.crypto.codec.Base64; //导入方法依赖的package包/类
private Object fromString(String s) throws IOException, ClassNotFoundException {
byte[] data = Base64.decode(s.getBytes());
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(data));
Object o = ois.readObject();
ois.close();
return o;
}
示例15: checkBasicAuthorization
import org.springframework.security.crypto.codec.Base64; //导入方法依赖的package包/类
private void checkBasicAuthorization(String authorization, HttpServletResponse httpResponse) throws IOException {
StringTokenizer tokenizer = new StringTokenizer(authorization);
if (tokenizer.countTokens() < 2) {
return;
}
if (!tokenizer.nextToken().equalsIgnoreCase("Basic")) {
return;
}
String base64 = tokenizer.nextToken();
String loginPassword = new String(Base64.decode(base64.getBytes(StandardCharsets.UTF_8)));
tokenizer = new StringTokenizer(loginPassword, ":");
checkUsernameAndPassword(tokenizer.nextToken(), tokenizer.nextToken(), httpResponse);
}