当前位置: 首页>>代码示例>>Java>>正文


Java Base64Utils.decodeFromString方法代码示例

本文整理汇总了Java中org.springframework.util.Base64Utils.decodeFromString方法的典型用法代码示例。如果您正苦于以下问题:Java Base64Utils.decodeFromString方法的具体用法?Java Base64Utils.decodeFromString怎么用?Java Base64Utils.decodeFromString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.util.Base64Utils的用法示例。


在下文中一共展示了Base64Utils.decodeFromString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setSigningKey

import org.springframework.util.Base64Utils; //导入方法依赖的package包/类
public void setSigningKey(String key) throws Exception {
	this.signingKey = key;
	key = key.trim();

	key = key.replace("-----BEGIN RSA PRIVATE KEY-----\n", "")
			.replace("-----END RSA PRIVATE KEY-----", "").trim().replace("\n", "");
	byte[] encoded = Base64Utils.decodeFromString(key);
	DerInputStream derInputStream = new DerInputStream(encoded);
	DerValue[] seq = derInputStream.getSequence(0);

	BigInteger modulus = seq[1].getBigInteger();
	BigInteger publicExp = seq[2].getBigInteger();
	BigInteger privateExp = seq[3].getBigInteger();
	BigInteger prime1 = seq[4].getBigInteger();
	BigInteger prime2 = seq[5].getBigInteger();
	BigInteger exp1 = seq[6].getBigInteger();
	BigInteger exp2 = seq[7].getBigInteger();
	BigInteger crtCoef = seq[8].getBigInteger();

	RSAPrivateCrtKeySpec keySpec = new RSAPrivateCrtKeySpec(modulus, publicExp,
			privateExp, prime1, prime2, exp1, exp2, crtCoef);
	KeyFactory kf = KeyFactory.getInstance("RSA");
	this.signer = new RSASSASigner(kf.generatePrivate(keySpec));
}
 
开发者ID:making,项目名称:spring-boot-actuator-dashboard,代码行数:25,代码来源:JwtTokenConverter.java

示例2: executeSignUp

import org.springframework.util.Base64Utils; //导入方法依赖的package包/类
@Override
@Transactional
public JsonResult executeSignUp(String account, String email, String cipher) throws Exception {
    account = new String(Base64Utils.decodeFromString(account), AppConstants.CHARSET_UTF8);
    email = new String(Base64Utils.decodeFromString(email), AppConstants.CHARSET_UTF8);
    cipher = new String(Base64Utils.decodeFromString(cipher), AppConstants.CHARSET_UTF8);

    SystemUserModel userModel = systemUserRepository.findByAccount(account);
    if (userModel != null && userModel.getId() != null) {
        return new JsonResult(400, "此用户账号已被注册!");
    }
    userModel = systemUserRepository.findByEmail(email);
    if (userModel != null && userModel.getId() != null) {
        return new JsonResult(400, "此邮箱地址已被注册!");
    }

    userModel = new SystemUserModel(IdWorker.INSTANCE.nextId(), account, cipher, email);
    systemUserRepository.save(userModel);
    return new JsonResult();
}
 
开发者ID:lupindong,项目名称:xq_seckill_microservice,代码行数:21,代码来源:UserServiceImpl.java

示例3: login

import org.springframework.util.Base64Utils; //导入方法依赖的package包/类
@PostMapping
@ResponseStatus(HttpStatus.OK)
public Authorization login(@RequestHeader(HttpHeaders.AUTHORIZATION) final String authorization) {
    if (authorization.isEmpty()) {
        log.warn("Authorization header is empty");
        throw new EmptyAuthorizationHeaderException();
    }
    if (authorization.startsWith("Basic ")) {
        final byte[] bytes = Base64Utils.decodeFromString(authorization.substring(6));
        final String decoded = new String(bytes);
        final String[] split = decoded.split(":");
        if (split.length == 2) {
            final String username = split[0];
            final String password = split[1];
            return authenticationService.login(username, password);
        }
        log.warn("Invalid basic authentication: {}", authorization);
        throw new InvalidBasicAuthenticationException(authorization);
    }
    log.warn("Unknown authorization scheme: {}", authorization);
    throw new UnknownAuthorizationSchemeException(authorization);
}
 
开发者ID:nus-ncl,项目名称:services-in-one,代码行数:23,代码来源:AuthenticationController.java

示例4: Base64MultipartFile

import org.springframework.util.Base64Utils; //导入方法依赖的package包/类
public Base64MultipartFile(String content) {
	if (StringUtils.isEmpty(content)) {
		throw new NullPointerException("图片内容不能为空.");
	}
	if (!content.startsWith("data:image")) {
		throw new IllegalArgumentException("非法图片格式.");
	}
	else if (content.startsWith("data:image/png;base64,")) {
		this.data = Base64Utils.decodeFromString(content.substring(22));
		this.extName = "png";
	}
	else if (content.startsWith("data:image/gif;base64,")) {
		this.data = Base64Utils.decodeFromString(content.substring(22));
		this.extName = "gif";
	}
	else if (content.startsWith("data:image/jpeg;base64,")) {
		this.data = Base64Utils.decodeFromString(content.substring(23));
		this.extName = "jpg";
	}
	else {
		throw new IllegalArgumentException("未知图片类型[" + StringUtils.substring(content, 0, 30) + "].");
	}
}
 
开发者ID:tanhaichao,项目名称:leopard,代码行数:24,代码来源:Base64MultipartFile.java

示例5: decodeFromString

import org.springframework.util.Base64Utils; //导入方法依赖的package包/类
public static byte[] decodeFromString(String str) {
	if (StringUtils.isEmpty(str)) {
		return null;
	}
	if (!str.startsWith("data:image")) {
		return null;
	}
	if (str.startsWith("data:image/png;base64,")) {
		return Base64Utils.decodeFromString(str.substring(22));
	}
	else if (str.startsWith("data:image/jpeg;base64,")) {
		return Base64Utils.decodeFromString(str.substring(23));
	}
	else {
		throw new IllegalArgumentException("未知图片类型.");
	}
}
 
开发者ID:tanhaichao,项目名称:leopard,代码行数:18,代码来源:Base64ImageUtil.java

示例6: decrypt

import org.springframework.util.Base64Utils; //导入方法依赖的package包/类
@Override
public byte[] decrypt(String keyName, String ciphertext,
		VaultTransitContext transitContext) {

	Assert.hasText(keyName, "KeyName must not be empty");
	Assert.hasText(ciphertext, "Cipher text must not be empty");
	Assert.notNull(transitContext, "VaultTransitContext must not be null");

	Map<String, String> request = new LinkedHashMap<>();

	request.put("ciphertext", ciphertext);

	applyTransitOptions(transitContext, request);

	String plaintext = (String) vaultOperations
			.write(String.format("%s/decrypt/%s", path, keyName), request)
			.getRequiredData().get("plaintext");

	return Base64Utils.decodeFromString(plaintext);
}
 
开发者ID:spring-projects,项目名称:spring-vault,代码行数:21,代码来源:VaultTransitTemplate.java

示例7: provisionCredentials

import org.springframework.util.Base64Utils; //导入方法依赖的package包/类
@Override
public CredentialsDto provisionCredentials(String applicationId, String credentialsBody)
    throws ControlServiceException {
  CredentialsDto credentials = new CredentialsDto(
      Base64Utils.decodeFromString(credentialsBody), CredentialsStatus.AVAILABLE);
  try {
    return this.credentialsServiceLocator
        .getCredentialsService(applicationId)
        .provideCredentials(credentials);
  } catch (CredentialsServiceException cause) {
    String message = MessageFormat
        .format("An unexpected exception occured while saving credentials [{0}]", credentials);
    LOG.error(message, cause);
    throw new ControlServiceException(cause);
  }
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:17,代码来源:DefaultControlService.java

示例8: getSignatureVerifier

import org.springframework.util.Base64Utils; //导入方法依赖的package包/类
@Override
public SignatureVerifier getSignatureVerifier() throws Exception {
    String publicKeyEndpointUri = getTokenEndpoint().replace("/token", "/certs");
    HttpEntity<Void> request = new HttpEntity<Void>(new HttpHeaders());
    LinkedHashMap<String, List<Map<String, Object>>> result =
        restTemplate.getForObject(publicKeyEndpointUri, LinkedHashMap.class);
    Map<String, Object> properties = result.get("keys").get(0);
    BigInteger modulus = new BigInteger(1, Base64Utils.decodeFromUrlSafeString((String) properties.get("n")));
    BigInteger publicExponent = new BigInteger(1, Base64Utils.decodeFromString((String) properties.get("e")));
    try {
        PublicKey publicKey =
            KeyFactory.getInstance("RSA").generatePublic(new RSAPublicKeySpec(modulus, publicExponent));
        RSAPublicKey rsaKey = (RSAPublicKey) RSAKeyFactory.toRSAKey(publicKey);
        return new RsaVerifier(rsaKey);
    } catch (GeneralSecurityException ex) {
        log.error("could not create key verifier", ex);
        throw ex;
    }
}
 
开发者ID:jhipster,项目名称:generator-jhipster,代码行数:20,代码来源:_KeycloakSignatureVerifierClient.java

示例9: executeSignIn

import org.springframework.util.Base64Utils; //导入方法依赖的package包/类
@Override
@Transactional
public JsonResult executeSignIn(HttpServletResponse response, String userAgent, String account, String cipher) throws Exception {
    JsonResult result = new JsonResult();

    account = new String(Base64Utils.decodeFromString(account), AppConstants.CHARSET_UTF8);
    cipher = new String(Base64Utils.decodeFromString(cipher), AppConstants.CHARSET_UTF8);

    SystemUserModel userModel = systemUserRepository.findByAccount(account);
    //FIXME 测试需要,暂时屏蔽
    /*if (userModel == null || userModel.getId() == null) {
        userModel = systemUserRepository.findByEmail(account);
        if (userModel == null || userModel.getId() == null) {
            return new JsonResult(400, "账号/邮箱或密码有误,请重新输入!");
        }
    }
    if (!cipher.equals(userModel.getPassword())) {
        return new JsonResult(400, "账号/邮箱或密码有误,请重新输入!");
    }*/

    // 生成Token
    JwtClaims claims = new JwtClaims(userModel.getAccount(), userAgent, userModel.getName());
    String token = JwtTokenUtil.generateToken(claims, appProperties.getJwtExpiration(), appProperties.getJwtSecretKey());
    result.setData(token);

    // 存入Cookie
    CookieUtil.createCookie(AppConstants.ACCESS_TOKEN, token, "lovexq.net", appProperties.getJwtExpiration(), true, response);
    CookieUtil.createCookie(AppConstants.USER_NAME, userModel.getName(), "lovexq.net", appProperties.getJwtExpiration(), response);

    // 缓存Token
    String cacheKey = AppConstants.CACHE_ACCESS_TOKEN + account;
    byteRedisClient.setByteObj(cacheKey, token, appProperties.getJwtExpiration());

    return result;
}
 
开发者ID:lupindong,项目名称:xq_seckill_microservice,代码行数:36,代码来源:UserServiceImpl.java

示例10: decode

import org.springframework.util.Base64Utils; //导入方法依赖的package包/类
private static byte[] decode(String content) {
	return Base64Utils.decodeFromString(content);
}
 
开发者ID:daima,项目名称:solo-spring,代码行数:4,代码来源:Base64Uploader.java

示例11: getSerializedState

import org.springframework.util.Base64Utils; //导入方法依赖的package包/类
@Override
protected byte[] getSerializedState(final HttpServletRequest request, final String id) {
    return Base64Utils.decodeFromString(id);
}
 
开发者ID:szegedi,项目名称:spring-web-jsflow,代码行数:5,代码来源:ClientSideFlowStateStorage.java

示例12: base64DataToInputStream

import org.springframework.util.Base64Utils; //导入方法依赖的package包/类
public static InputStream base64DataToInputStream(String base64Data){
	byte[] bytes=Base64Utils.decodeFromString(base64Data);
	ByteArrayInputStream inputStream=new ByteArrayInputStream(bytes);
	return inputStream;
}
 
开发者ID:youseries,项目名称:ureport,代码行数:6,代码来源:ImageUtils.java

示例13: getApiReq

import org.springframework.util.Base64Utils; //导入方法依赖的package包/类
private static ApiReq getApiReq(String encodeReq) throws IOException {
    String decodeReq = new String(Base64Utils.decodeFromString(encodeReq));
    ApiReq apiReq = JsonUtil.parse(decodeReq, ApiReq.class);
    return apiReq;
}
 
开发者ID:slking1987,项目名称:mafia,代码行数:6,代码来源:ApiUtil.java

示例14: deserialize

import org.springframework.util.Base64Utils; //导入方法依赖的package包/类
@Override
public byte[] deserialize(JsonElement json, Type type, JsonDeserializationContext cxt) {
	return Base64Utils.decodeFromString(json.getAsString());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:5,代码来源:GsonBuilderUtils.java

示例15: testBase64

import org.springframework.util.Base64Utils; //导入方法依赖的package包/类
@Test
public void testBase64(){
   //NTQ2OTAzOGItMDk4YS00ZGFiLWJiMzctMjVjNzYxZTY0YTZl
    String decodeToken = new String(Base64Utils.decodeFromString("NTQ2OTAzOGItMDk4YS00ZGFiLWJiMzctMjVjNzYxZTY0YTZl"));
    System.out.println(decodeToken);
}
 
开发者ID:fku233,项目名称:MBLive,代码行数:7,代码来源:SendEmailTest.java


注:本文中的org.springframework.util.Base64Utils.decodeFromString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。