當前位置: 首頁>>代碼示例>>Java>>正文


Java Base64Utils類代碼示例

本文整理匯總了Java中org.springframework.util.Base64Utils的典型用法代碼示例。如果您正苦於以下問題:Java Base64Utils類的具體用法?Java Base64Utils怎麽用?Java Base64Utils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Base64Utils類屬於org.springframework.util包,在下文中一共展示了Base64Utils類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getComments

import org.springframework.util.Base64Utils; //導入依賴的package包/類
@HystrixCommand(fallbackMethod = "defaultComments")
public List<Comment> getComments(Image image, String sessionId) {

	ResponseEntity<List<Comment>> results = restTemplate.exchange(
		"http://COMMENTS/comments/{imageId}",
		HttpMethod.GET,
		new HttpEntity<>(new HttpHeaders() {{
			String credentials = imagesConfiguration.getCommentsUser() + ":" +
				imagesConfiguration.getCommentsPassword();
			String token = new String(Base64Utils.encode(credentials.getBytes()));
			set(AUTHORIZATION, "Basic " + token);
			set("Cookie", "SESSION=" + sessionId);
		}}),
		new ParameterizedTypeReference<List<Comment>>() {},
		image.getId());
	return results.getBody();
}
 
開發者ID:PacktPublishing,項目名稱:Learning-Spring-Boot-2.0-Second-Edition,代碼行數:18,代碼來源:CommentHelper.java

示例2: 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

示例3: getComments

import org.springframework.util.Base64Utils; //導入依賴的package包/類
@HystrixCommand(fallbackMethod = "defaultComments")
public List<Comment> getComments(Image image, String sessionId) {

	ResponseEntity<List<Comment>> results = restTemplate.exchange(
		"http://COMMENTS/comments/{imageId}",
		HttpMethod.GET,
		new HttpEntity<>(new HttpHeaders() {{
			String credentials = imagesConfiguration.getCommentsUser() + ":" +
				imagesConfiguration.getCommentsPassword();
			String token = new String(Base64Utils.encode(credentials.getBytes()));
			set(AUTHORIZATION, "Basic " + token);
			set("SESSION", sessionId);
		}}),
		new ParameterizedTypeReference<List<Comment>>() {},
		image.getId());
	return results.getBody();
}
 
開發者ID:PacktPublishing,項目名稱:Learning-Spring-Boot-2.0-Second-Edition,代碼行數:18,代碼來源:CommentHelper.java

示例4: getAllUserProfiles

import org.springframework.util.Base64Utils; //導入依賴的package包/類
@Test
@Transactional
public void getAllUserProfiles() throws Exception {
    // Initialize the database
    userProfileRepository.saveAndFlush(userProfile);

    // Get all the userProfiles
    restUserProfileMockMvc.perform(get("/api/userProfiles"))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON))
            .andExpect(jsonPath("$.[*].id").value(hasItem(userProfile.getId().intValue())))
            .andExpect(jsonPath("$.[*].phones").value(hasItem(DEFAULT_PHONES.toString())))
            .andExpect(jsonPath("$.[*].address").value(hasItem(DEFAULT_ADDRESS.toString())))
            .andExpect(jsonPath("$.[*].pictureContentType").value(hasItem(DEFAULT_PICTURE_CONTENT_TYPE)))
            .andExpect(jsonPath("$.[*].picture").value(hasItem(Base64Utils.encodeToString(DEFAULT_PICTURE))));
}
 
開發者ID:GastonMauroDiaz,項目名稱:buenojo,代碼行數:17,代碼來源:UserProfileResourceTest.java

示例5: getUserProfile

import org.springframework.util.Base64Utils; //導入依賴的package包/類
@Test
@Transactional
public void getUserProfile() throws Exception {
    // Initialize the database
    userProfileRepository.saveAndFlush(userProfile);

    // Get the userProfile
    restUserProfileMockMvc.perform(get("/api/userProfiles/{id}", userProfile.getId()))
        .andExpect(status().isOk())
        .andExpect(content().contentType(MediaType.APPLICATION_JSON))
        .andExpect(jsonPath("$.id").value(userProfile.getId().intValue()))
        .andExpect(jsonPath("$.phones").value(DEFAULT_PHONES.toString()))
        .andExpect(jsonPath("$.address").value(DEFAULT_ADDRESS.toString()))
        .andExpect(jsonPath("$.pictureContentType").value(DEFAULT_PICTURE_CONTENT_TYPE))
        .andExpect(jsonPath("$.picture").value(Base64Utils.encodeToString(DEFAULT_PICTURE)));
}
 
開發者ID:GastonMauroDiaz,項目名稱:buenojo,代碼行數:17,代碼來源:UserProfileResourceTest.java

示例6: getAllImageResources

import org.springframework.util.Base64Utils; //導入依賴的package包/類
@Test
@Transactional
public void getAllImageResources() throws Exception {
    // Initialize the database
    imageResourceRepository.saveAndFlush(imageResource);

    // Get all the imageResources
    restImageResourceMockMvc.perform(get("/api/imageResources"))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON))
            .andExpect(jsonPath("$.[*].id").value(hasItem(imageResource.getId().intValue())))
            .andExpect(jsonPath("$.[*].name").value(hasItem(DEFAULT_NAME.toString())))
            .andExpect(jsonPath("$.[*].loResImageContentType").value(hasItem(DEFAULT_LO_RES_IMAGE_CONTENT_TYPE)))
            .andExpect(jsonPath("$.[*].loResImage").value(hasItem(Base64Utils.encodeToString(DEFAULT_LO_RES_IMAGE))))
            .andExpect(jsonPath("$.[*].hiResImageContentType").value(hasItem(DEFAULT_HI_RES_IMAGE_CONTENT_TYPE)))
            .andExpect(jsonPath("$.[*].hiResImage").value(hasItem(Base64Utils.encodeToString(DEFAULT_HI_RES_IMAGE))));
}
 
開發者ID:GastonMauroDiaz,項目名稱:buenojo,代碼行數:18,代碼來源:ImageResourceResourceTest.java

示例7: getImageResource

import org.springframework.util.Base64Utils; //導入依賴的package包/類
@Test
@Transactional
public void getImageResource() throws Exception {
    // Initialize the database
    imageResourceRepository.saveAndFlush(imageResource);

    // Get the imageResource
    restImageResourceMockMvc.perform(get("/api/imageResources/{id}", imageResource.getId()))
        .andExpect(status().isOk())
        .andExpect(content().contentType(MediaType.APPLICATION_JSON))
        .andExpect(jsonPath("$.id").value(imageResource.getId().intValue()))
        .andExpect(jsonPath("$.name").value(DEFAULT_NAME.toString()))
        .andExpect(jsonPath("$.loResImageContentType").value(DEFAULT_LO_RES_IMAGE_CONTENT_TYPE))
        .andExpect(jsonPath("$.loResImage").value(Base64Utils.encodeToString(DEFAULT_LO_RES_IMAGE)))
        .andExpect(jsonPath("$.hiResImageContentType").value(DEFAULT_HI_RES_IMAGE_CONTENT_TYPE))
        .andExpect(jsonPath("$.hiResImage").value(Base64Utils.encodeToString(DEFAULT_HI_RES_IMAGE)));
}
 
開發者ID:GastonMauroDiaz,項目名稱:buenojo,代碼行數:18,代碼來源:ImageResourceResourceTest.java

示例8: exceptionHandler

import org.springframework.util.Base64Utils; //導入依賴的package包/類
public void exceptionHandler(HttpServletRequest request, HttpServletResponse response,
                              Object handler, Exception e) throws Throwable {

    logger.debug("exceptionHandler->" + e + ",handler->" + handler);

    logger.debug("getAttribute -> " + request.getAttribute(Constants.defaultResponseHeader));
    if (Constants.defaultResponseHeader.equals(request.getAttribute(Constants.defaultResponseHeader))) {
        response.setHeader(Constants.defaultResponseHeader, Constants.defaultResponseHeader);
    } else {
        logger.debug(e.getMessage());
        String localizedMessage = e.getLocalizedMessage();
        String msg = e.getMessage();
        String className = e.getClass().getName();
        ExcepModel excepModel = new ExcepModel(localizedMessage, msg, className);
        response.setHeader(Constants.exceptionHeader, Base64Utils.encodeToString(excepModel.toJsonString().getBytes()));
    }

}
 
開發者ID:codingapi,項目名稱:filter,代碼行數:19,代碼來源:DefFilterExceptionHandler.java

示例9: getAllProducts

import org.springframework.util.Base64Utils; //導入依賴的package包/類
@Test
@Transactional
public void getAllProducts() throws Exception {
    // Initialize the database
    productRepository.saveAndFlush(product);

    // Get all the productList
    restProductMockMvc.perform(get("/api/products?sort=id,desc"))
        .andExpect(status().isOk())
        .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
        .andExpect(jsonPath("$.[*].id").value(hasItem(product.getId().intValue())))
        .andExpect(jsonPath("$.[*].name").value(hasItem(DEFAULT_NAME.toString())))
        .andExpect(jsonPath("$.[*].description").value(hasItem(DEFAULT_DESCRIPTION.toString())))
        .andExpect(jsonPath("$.[*].imageContentType").value(hasItem(DEFAULT_IMAGE_CONTENT_TYPE)))
        .andExpect(jsonPath("$.[*].image").value(hasItem(Base64Utils.encodeToString(DEFAULT_IMAGE))))
        .andExpect(jsonPath("$.[*].price").value(hasItem(DEFAULT_PRICE.intValue())))
        .andExpect(jsonPath("$.[*].size").value(hasItem(DEFAULT_SIZE.toString())))
        .andExpect(jsonPath("$.[*].availableUntil").value(hasItem(DEFAULT_AVAILABLE_UNTIL.toString())));
}
 
開發者ID:deepu105,項目名稱:spring-io,代碼行數:20,代碼來源:ProductResourceIntTest.java

示例10: getProduct

import org.springframework.util.Base64Utils; //導入依賴的package包/類
@Test
@Transactional
public void getProduct() throws Exception {
    // Initialize the database
    productRepository.saveAndFlush(product);

    // Get the product
    restProductMockMvc.perform(get("/api/products/{id}", product.getId()))
        .andExpect(status().isOk())
        .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
        .andExpect(jsonPath("$.id").value(product.getId().intValue()))
        .andExpect(jsonPath("$.name").value(DEFAULT_NAME.toString()))
        .andExpect(jsonPath("$.description").value(DEFAULT_DESCRIPTION.toString()))
        .andExpect(jsonPath("$.imageContentType").value(DEFAULT_IMAGE_CONTENT_TYPE))
        .andExpect(jsonPath("$.image").value(Base64Utils.encodeToString(DEFAULT_IMAGE)))
        .andExpect(jsonPath("$.price").value(DEFAULT_PRICE.intValue()))
        .andExpect(jsonPath("$.size").value(DEFAULT_SIZE.toString()))
        .andExpect(jsonPath("$.availableUntil").value(DEFAULT_AVAILABLE_UNTIL.toString()));
}
 
開發者ID:deepu105,項目名稱:spring-io,代碼行數:20,代碼來源:ProductResourceIntTest.java

示例11: searchProduct

import org.springframework.util.Base64Utils; //導入依賴的package包/類
@Test
@Transactional
public void searchProduct() throws Exception {
    // Initialize the database
    productService.save(product);

    // Search the product
    restProductMockMvc.perform(get("/api/_search/products?query=id:" + product.getId()))
        .andExpect(status().isOk())
        .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
        .andExpect(jsonPath("$.[*].id").value(hasItem(product.getId().intValue())))
        .andExpect(jsonPath("$.[*].name").value(hasItem(DEFAULT_NAME.toString())))
        .andExpect(jsonPath("$.[*].description").value(hasItem(DEFAULT_DESCRIPTION.toString())))
        .andExpect(jsonPath("$.[*].imageContentType").value(hasItem(DEFAULT_IMAGE_CONTENT_TYPE)))
        .andExpect(jsonPath("$.[*].image").value(hasItem(Base64Utils.encodeToString(DEFAULT_IMAGE))))
        .andExpect(jsonPath("$.[*].price").value(hasItem(DEFAULT_PRICE.intValue())))
        .andExpect(jsonPath("$.[*].size").value(hasItem(DEFAULT_SIZE.toString())))
        .andExpect(jsonPath("$.[*].availableUntil").value(hasItem(DEFAULT_AVAILABLE_UNTIL.toString())));
}
 
開發者ID:deepu105,項目名稱:spring-io,代碼行數:20,代碼來源:ProductResourceIntTest.java

示例12: 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

示例13: getKeys

import org.springframework.util.Base64Utils; //導入依賴的package包/類
public static HashMap<String, String> getKeys() {
	try {
		HashMap<String, String> map = new HashMap<>();
		KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance(SIGN_ALGORITHM);
		keyPairGen.initialize(1024);
		KeyPair keyPair = keyPairGen.generateKeyPair();
		RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
		RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();
		map.put(PUBLIC_KEY, new String(Base64Utils.encode(publicKey.getEncoded())));
		map.put(PRIVATE_KEY, new String(Base64Utils.encode(privateKey.getEncoded())));
		return map;
	} catch (Exception e) {
		e.printStackTrace();
		throw new CustomException("生成秘鑰對失敗");
	}
}
 
開發者ID:zhaoqilong3031,項目名稱:spring-cloud-samples,代碼行數:17,代碼來源:RSAUtils.java

示例14: findGroupMessageList

import org.springframework.util.Base64Utils; //導入依賴的package包/類
private List<MessageEntity> findGroupMessageList(List<? extends IMGroupMessageEntity> messageList) {
    List<MessageEntity> resultList = new ArrayList<>();
    for (IMGroupMessageEntity message : messageList) {
        MessageEntity messageEntity = new MessageEntity();
        messageEntity.setId(message.getId());
        messageEntity.setMsgId(message.getMsgId());
        if (message.getType() == IMBaseDefine.MsgType.MSG_TYPE_GROUP_AUDIO_VALUE) {
            // 語音Base64
            byte[] audioData = audioInternalService.readAudioInfo(Long.valueOf(message.getContent()));
            messageEntity.setContent(Base64Utils.encodeToString(audioData));
        } else {
            messageEntity.setContent(message.getContent());
        }
        messageEntity.setFromId(message.getUserId());
        messageEntity.setCreated(message.getCreated());
        messageEntity.setStatus(message.getStatus());
        messageEntity.setMsgType(message.getType());

        resultList.add(messageEntity);
    }
    return resultList;
}
 
開發者ID:ccfish86,項目名稱:sctalk,代碼行數:23,代碼來源:MessageServiceController.java

示例15: findMessageList

import org.springframework.util.Base64Utils; //導入依賴的package包/類
private List<MessageEntity> findMessageList(List<? extends IMMessageEntity> messageList) {
    List<MessageEntity> resultList = new ArrayList<>();
    for (IMMessageEntity message : messageList) {
        MessageEntity messageEntity = new MessageEntity();
        messageEntity.setId(message.getId());
        messageEntity.setMsgId(message.getMsgId());
        if (message.getType() == IMBaseDefine.MsgType.MSG_TYPE_SINGLE_AUDIO_VALUE) {
            // 語音Base64
            byte[] audioData = audioInternalService.readAudioInfo(Long.valueOf(message.getContent()));
            messageEntity.setContent(Base64Utils.encodeToString(audioData));
        } else {
            messageEntity.setContent(message.getContent());
        }
        messageEntity.setFromId(message.getUserId());
        messageEntity.setCreated(message.getCreated());
        messageEntity.setStatus(message.getStatus());
        messageEntity.setMsgType(message.getType());
        resultList.add(messageEntity);
    }
    return resultList;
}
 
開發者ID:ccfish86,項目名稱:sctalk,代碼行數:22,代碼來源:MessageServiceController.java


注:本文中的org.springframework.util.Base64Utils類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。