本文整理汇总了Java中org.springframework.security.crypto.codec.Base64类的典型用法代码示例。如果您正苦于以下问题:Java Base64类的具体用法?Java Base64怎么用?Java Base64使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Base64类属于org.springframework.security.crypto.codec包,在下文中一共展示了Base64类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getKeyFromConfigServer
import org.springframework.security.crypto.codec.Base64; //导入依赖的package包/类
private String getKeyFromConfigServer(RestTemplate keyUriRestTemplate) throws CertificateException {
// Load available UAA servers
discoveryClient.getServices();
HttpEntity<Void> request = new HttpEntity<Void>(new HttpHeaders());
String content = keyUriRestTemplate
.exchange("http://config/api/token_key", HttpMethod.GET, request, String.class).getBody();
if (StringUtils.isBlank(content)) {
throw new CertificateException("Received empty certificate from config.");
}
InputStream fin = new ByteArrayInputStream(content.getBytes());
CertificateFactory f = CertificateFactory.getInstance(Constants.CERTIFICATE);
X509Certificate certificate = (X509Certificate)f.generateCertificate(fin);
PublicKey pk = certificate.getPublicKey();
return String.format(Constants.PUBLIC_KEY, new String(Base64.encode(pk.getEncoded())));
}
示例2: 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)};
}
}
示例3: getKeyFromAuthorizationServer
import org.springframework.security.crypto.codec.Base64; //导入依赖的package包/类
private String getKeyFromAuthorizationServer(RestTemplate keyUriRestTemplate) throws CertificateException {
// Load available UAA servers
discoveryClient.getServices();
HttpEntity<Void> request = new HttpEntity<Void>(new HttpHeaders());
String content = keyUriRestTemplate
.exchange("http://config/api/token_key", HttpMethod.GET, request, String.class).getBody();
if (StringUtils.isBlank(content)) {
throw new CertificateException("Received empty certificate from config.");
}
InputStream fin = new ByteArrayInputStream(content.getBytes());
CertificateFactory f = CertificateFactory.getInstance(Constants.CERTIFICATE);
X509Certificate certificate = (X509Certificate)f.generateCertificate(fin);
PublicKey pk = certificate.getPublicKey();
return String.format(Constants.PUBLIC_KEY, new String(Base64.encode(pk.getEncoded())));
}
示例4: createHeaders
import org.springframework.security.crypto.codec.Base64; //导入依赖的package包/类
static HttpHeaders createHeaders(final String username, final String password) {
return new HttpHeaders() {
/**
*
*/
private static final long serialVersionUID = 1L;
{
String auth = username + ":" + password;
byte[] encodedAuth = Base64.encode(
auth.getBytes(Charset.forName("US-ASCII")));
String authHeader = "Basic " + new String(encodedAuth);
set("Authorization", authHeader);
}
};
}
示例5: allowsGetRequestsButRejectsPostForUser
import org.springframework.security.crypto.codec.Base64; //导入依赖的package包/类
@Test
public void allowsGetRequestsButRejectsPostForUser() throws Exception {
HttpHeaders headers = new HttpHeaders();
headers.add(HttpHeaders.ACCEPT, MediaTypes.HAL_JSON_VALUE);
headers.add(HttpHeaders.AUTHORIZATION, "Basic " + new String(Base64.encode(("greg:turnquist").getBytes())));
mvc.perform(get("/employees").//
headers(headers)).//
andExpect(content().contentTypeCompatibleWith(MediaTypes.HAL_JSON)).//
andExpect(status().isOk()).//
andDo(print());
mvc.perform(post("/employees").//
headers(headers)).//
andExpect(status().isForbidden()).//
andDo(print());
}
示例6: 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) };
}
示例7: getWebSocketHttpHeaders
import org.springframework.security.crypto.codec.Base64; //导入依赖的package包/类
public WebSocketHttpHeaders getWebSocketHttpHeaders(
WebSocketSession userAgentSession) {
WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
Principal principal = userAgentSession.getPrincipal();
if (principal != null) {
Authentication authentication = (Authentication) principal;
String usernameColonPwd = authentication.getName() + ":"
+ authentication.getCredentials().toString();
String encodedCredentials = new String(
Base64.encode(usernameColonPwd.getBytes()));
headers.put(HttpHeaders.AUTHORIZATION,
Collections.singletonList("Basic " + encodedCredentials));
if(logger.isDebugEnabled()) {
logger.debug("Added basic authentication header for user " + principal.getName() + " to web sockets http headers");
}
}
else {
if(logger.isDebugEnabled()) {
logger.debug("Skipped adding basic authentication header since user session principal is null");
}
}
return headers;
}
开发者ID:mthizo247,项目名称:spring-cloud-netflix-zuul-websocket,代码行数:24,代码来源:BasicAuthPrincipalHeadersCallback.java
示例8: 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));
}
示例9: createHttpEntity
import org.springframework.security.crypto.codec.Base64; //导入依赖的package包/类
/**
* Creates a Http Entity
* @param entity entity to be created from
* @param <H> generic passed in for body content
* @return HttpEntity containing object as JSON
*/
public <H> HttpEntity<H> createHttpEntity(H entity) {
HttpHeaders headers = new HttpHeaders();
headers.set(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE);
headers.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
if (this.config.getUsername() != null && this.config.getPassword() != null) {
String auth = this.config.getUsername() + ":" + this.config.getPassword();
byte[] encodedAuth = Base64.encode(auth.getBytes(Charset.forName("US-ASCII")));
String authHeader = "Basic " + new String(encodedAuth);
headers.set("Authorization", authHeader);
}
HttpEntity<H> httpEntity = new HttpEntity<H>(entity, headers);
return httpEntity;
}
示例10: createDir
import org.springframework.security.crypto.codec.Base64; //导入依赖的package包/类
public static void createDir(ZookeeperCredentials credentials, String path) throws Exception {
CuratorFramework tempClient = getNewTempClient(credentials.getConnectionString());
MessageDigest md = MessageDigest.getInstance("SHA-1");
byte[] authDigest =
md.digest(String.format("%s:%s", credentials.getUsername(), credentials.getPassword())
.getBytes());
String authEncoded = new String(Base64.encode(authDigest));
ImmutableList<ACL> acl =
ImmutableList.of(new ACL(ZooDefs.Perms.ALL, new Id("digest", String.format("%s:%s",
credentials.getUsername(), authEncoded))));
tempClient.create().creatingParentsIfNeeded().withACL(acl).forPath(path);
tempClient.close();
}
示例11: 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
示例12: 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) };
}
示例13: interceptInner
import org.springframework.security.crypto.codec.Base64; //导入依赖的package包/类
private void interceptInner(HttpHeaders headers, HttpRequest httpRequest) {
URI uri = httpRequest.getURI();
String host = uri.getHost();
int port = uri.getPort();
String url = host + (port == -1 ? "" : ":" + port);
String name = registryName.get();
log.debug("try to auth request to registry: {}", name);
RegistryService registry = registryRepository.getByName(name);
if (registry == null) {
log.debug("auth : none due to unknown registry \"{}\"", name);
return;
}
RegistryCredentials credentials = registry.getCredentials();
if (credentials == null || !StringUtils.hasText(credentials.getPassword())) {
log.debug("auth : none due to unknown registry \"{}\"", name);
return;
}
String result = format("'{'\"username\":\"{0}\",\"password\":\"{1}\",\"email\":\"[email protected]\",\"serveraddress\":\"{2}\",\"auth\":\"\"'}'",
credentials.getUsername(), credentials.getPassword(), url);
log.debug("auth : {}", result);
String xRegistryAuth = new String(Base64.encode(result.getBytes()));
log.debug("X-Registry-Auth : [{}]", xRegistryAuth);
headers.add("X-Registry-Auth", xRegistryAuth);
}
示例14: Encriptar
import org.springframework.security.crypto.codec.Base64; //导入依赖的package包/类
public static String Encriptar(String texto) {
String base64EncryptedString = "";
try {
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 cipher = Cipher.getInstance("DESede");
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] plainTextBytes = texto.getBytes("utf-8");
byte[] buf = cipher.doFinal(plainTextBytes);
byte[] base64Bytes = Base64.encode(buf);
base64EncryptedString = new String(base64Bytes);
} catch (Exception ex) {
}
return base64EncryptedString;
}
示例15: 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;
}