本文整理汇总了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));
}
示例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();
}
示例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);
}
示例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) + "].");
}
}
示例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("未知图片类型.");
}
}
示例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);
}
示例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);
}
}
示例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;
}
}
示例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;
}
示例10: decode
import org.springframework.util.Base64Utils; //导入方法依赖的package包/类
private static byte[] decode(String content) {
return Base64Utils.decodeFromString(content);
}
示例11: getSerializedState
import org.springframework.util.Base64Utils; //导入方法依赖的package包/类
@Override
protected byte[] getSerializedState(final HttpServletRequest request, final String id) {
return Base64Utils.decodeFromString(id);
}
示例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;
}
示例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;
}
示例14: deserialize
import org.springframework.util.Base64Utils; //导入方法依赖的package包/类
@Override
public byte[] deserialize(JsonElement json, Type type, JsonDeserializationContext cxt) {
return Base64Utils.decodeFromString(json.getAsString());
}
示例15: testBase64
import org.springframework.util.Base64Utils; //导入方法依赖的package包/类
@Test
public void testBase64(){
//NTQ2OTAzOGItMDk4YS00ZGFiLWJiMzctMjVjNzYxZTY0YTZl
String decodeToken = new String(Base64Utils.decodeFromString("NTQ2OTAzOGItMDk4YS00ZGFiLWJiMzctMjVjNzYxZTY0YTZl"));
System.out.println(decodeToken);
}