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


Java Base64类代码示例

本文整理汇总了Java中org.apache.tomcat.util.codec.binary.Base64的典型用法代码示例。如果您正苦于以下问题:Java Base64类的具体用法?Java Base64怎么用?Java Base64使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: uploadLogo

import org.apache.tomcat.util.codec.binary.Base64; //导入依赖的package包/类
@RequestMapping(value = "/{id}/uploadLogo", method = RequestMethod.POST)
@ApiOperation(value = "Add new upload Logo")
public String uploadLogo(@ApiParam(value = "Organization Id", required = true)
                         @PathVariable Integer id,
                         @ApiParam(value = "Request Body", required = true)
                         @RequestBody String logoFileContent) {
    try {
        byte[] imageByte = Base64.decodeBase64(logoFileContent);
        File directory = new File(LOGO_UPLOAD.getValue());
        if (!directory.exists()) {
            directory.mkdir();
        }
        File f = new File(organizationService.getLogoUploadPath(id));
        new FileOutputStream(f).write(imageByte);
        return "Success";
    } catch (Exception e) {
        return "Error saving logo for organization " + id + " : " + e;
    }
}
 
开发者ID:Code4SocialGood,项目名称:C4SG-Obsolete,代码行数:20,代码来源:OrganizationController.java

示例2: retrieveOrganizationLogo

import org.apache.tomcat.util.codec.binary.Base64; //导入依赖的package包/类
@CrossOrigin
@RequestMapping(value = "/{id}/getLogo", method = RequestMethod.GET)
@ApiOperation(value = "Retrieves organization logo")
public String retrieveOrganizationLogo(@ApiParam(value = "Organization id to get logo for", required = true)
                                     @PathVariable("id") int id) {
    File logo = new File(organizationService.getLogoUploadPath(id));
    try {
        FileInputStream fileInputStreamReader = new FileInputStream(logo);
        byte[] bytes = new byte[(int) logo.length()];
        fileInputStreamReader.read(bytes);
        return new String(Base64.encodeBase64(bytes));
    } catch (IOException e) {
        e.printStackTrace();
    return null;
}
}
 
开发者ID:Code4SocialGood,项目名称:C4SG-Obsolete,代码行数:17,代码来源:OrganizationController.java

示例3: deleteShortUrl

import org.apache.tomcat.util.codec.binary.Base64; //导入依赖的package包/类
/**
 * This method deletes the url for code
 * 
 * @param code
 */
public void deleteShortUrl(String code) {
	try {
		// get the object
		ObjectMetadata metaData = this.s3Client.getObjectMetadata(this.bucket, code);
		String url = metaData.getUserMetaDataOf("url");
		logger.info("The url to be deleted {}", url);
		this.s3Client.deleteObject(this.bucket, code);
		this.s3Client.deleteObject(this.bucket + "-dummy", code + Base64.encodeBase64String(url.getBytes()));

	} catch (AmazonS3Exception ex) {
		if (ex.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
			return;
		}
		logger.warn("Unable to get object status", ex);
		throw ex;
	}

}
 
开发者ID:weblegit,项目名称:urlshortner,代码行数:24,代码来源:UrlShortnerService.java

示例4: sendVerificationEmail

import org.apache.tomcat.util.codec.binary.Base64; //导入依赖的package包/类
private void sendVerificationEmail(User user) {
    final Map<String, String> map = new HashMap<>();
    map.put("firstname", user.getUserDetails().getFirstName());
    map.put("domain", domainProperties.getDomain());
    map.put("id", user.getId());
    // email address may contain special characters (e.g. '+') which does not form a valid URI
    map.put("email", Base64.encodeBase64String(user.getUserDetails().getEmail().getBytes()));
    map.put("key", user.getVerificationKey());

    /*
     * If sending email fails, we catch the exceptions and log them,
     * rather than throw the exceptions. Hence, the email will not cause
     * the main application to fail. If users cannot receive emails after
     * a certain amount of time, they should send email to [email protected]
     */
    try {
        String msgText = FreeMarkerTemplateUtils.processTemplateIntoString(
                emailValidationTemplate, map);
        mailService.send(TESTBED_EMAIL, user.getUserDetails().getEmail(),
                "Please Verify Your Email Address", msgText, false, null, null);
        log.debug("Email sent: {}", msgText);
    } catch (IOException | TemplateException e) {
        log.warn("{}", e);
    }

}
 
开发者ID:nus-ncl,项目名称:services-in-one,代码行数:27,代码来源:RegistrationServiceImpl.java

示例5: decrypt

import org.apache.tomcat.util.codec.binary.Base64; //导入依赖的package包/类
/**
 * 带向量的解密
 * @param str
 * @param secretKey
 * @param iv
 * @return
    * @throws Exception
    */
public static String decrypt(String str, String secretKey, byte[] iv) throws Exception {
	if (str == null || "".equals(str)) {
		return str;
	}
	String str1 = URLDecoder.decode(str, "UTF-8");
	byte str2[] = Base64.decodeBase64(str1.getBytes());
	IvParameterSpec zeroIv = new IvParameterSpec(iv);
	SecretKeySpec key = new SecretKeySpec(secretKey.getBytes("UTF-8"), "DES");
	Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
	cipher.init(Cipher.DECRYPT_MODE, key, zeroIv);
	byte[] str3 = cipher.doFinal(str2);
	String res = str;
	if (str3 != null) {
		res = new String(str3, "UTF-8");
	}
	return res;
}
 
开发者ID:ggj2010,项目名称:javabase,代码行数:26,代码来源:DesUtil.java

示例6: BasicCredentials

import org.apache.tomcat.util.codec.binary.Base64; //导入依赖的package包/类
private BasicCredentials(String aMethod,
        String aUsername, String aPassword) {
    method = aMethod;
    username = aUsername;
    password = aPassword;
    String userCredentials = username + ":" + password;
    byte[] credentialsBytes =
            userCredentials.getBytes(B2CConverter.ISO_8859_1);
    String base64auth = Base64.encodeBase64String(credentialsBytes);
    credentials= method + " " + base64auth;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:12,代码来源:TestSSOnonLoginAndBasicAuthenticator.java

示例7: BasicCredentials

import org.apache.tomcat.util.codec.binary.Base64; //导入依赖的package包/类
private BasicCredentials(String aMethod, String aUsername, String aPassword) {
    method = aMethod;
    username = aUsername;
    password = aPassword;
    String userCredentials = username + ":" + password;
    byte[] credentialsBytes = userCredentials.getBytes(B2CConverter.ISO_8859_1);
    String base64auth = Base64.encodeBase64String(credentialsBytes);
    credentials = method + " " + base64auth;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:10,代码来源:TestRestCsrfPreventionFilter2.java

示例8: rfc4648Base64Encode

import org.apache.tomcat.util.codec.binary.Base64; //导入依赖的package包/类
static String rfc4648Base64Encode(String arg) throws UnsupportedEncodingException {
	String res = Base64.encodeBase64String(arg.getBytes(TEXT_ENCODING));//encoder.encodeToString(arg.getBytes(TEXT_ENCODING));
	res = res.replace("/", "_");
	res = res.replace("+", "-");
	res = res.replace("=", "");
	return res;
}
 
开发者ID:sshubhadeep,项目名称:PowerBIEmbeddedJavaImplementation,代码行数:8,代码来源:AppTokenCreator.java

示例9: createDummyRecord

import org.apache.tomcat.util.codec.binary.Base64; //导入依赖的package包/类
private void createDummyRecord(String url, String code) {
	// Add a dummy object for pointer
	byte[] dummyFileContentBytes = new String(code).getBytes(StandardCharsets.UTF_8);
	InputStream fileInputStream = new ByteArrayInputStream(dummyFileContentBytes);
	ObjectMetadata metadata = new ObjectMetadata();
	metadata.setContentType("text/html");
	metadata.setContentLength(dummyFileContentBytes.length);
	PutObjectRequest putObjectRequest = new PutObjectRequest(this.bucket + "-dummy", code
			+ Base64.encodeBase64String(url.getBytes()), fileInputStream, metadata);
	this.s3Client.putObject(putObjectRequest);
}
 
开发者ID:weblegit,项目名称:urlshortner,代码行数:12,代码来源:UrlShortnerService.java

示例10: getShortUrlList

import org.apache.tomcat.util.codec.binary.Base64; //导入依赖的package包/类
/**
 * The method lists down all the short url codes and their corresponding
 * urls
 * 
 * @return
 */
public List<ShortUrl> getShortUrlList() {

	ObjectListing objectList = this.s3Client.listObjects(bucket + "-dummy");
	List<ShortUrl> shortUrlList = new LinkedList<>();

	for (S3ObjectSummary s3ObjectSummary : objectList.getObjectSummaries()) {
		String url = s3ObjectSummary.getKey().substring(6);
		shortUrlList.add(new ShortUrl(new String(Base64.decodeBase64(url)), s3ObjectSummary.getKey()
				.substring(0, 6)));
	}
	return shortUrlList;
}
 
开发者ID:weblegit,项目名称:urlshortner,代码行数:19,代码来源:UrlShortnerService.java

示例11: writeChunk

import org.apache.tomcat.util.codec.binary.Base64; //导入依赖的package包/类
private void writeChunk(ResumableEntity entity, int resumableChunkNumber, ResumableInfo resumableInfo) {
    try (RandomAccessFile raf = new RandomAccessFile(entity.getResumableFilePath(), "rw")) {
        //Seek to position
        log.info("resumableChunkNumber: " + resumableChunkNumber + " resumableChunkSize: " + entity.getResumableChunkSize());
        raf.seek((resumableChunkNumber - 1) * (long) entity.getResumableChunkSize());
        //Save to file
        byte[] bytes = Base64.decodeBase64(resumableInfo.getResumableChunk());
        raf.write(bytes);
    } catch (Exception e) {
        log.error("Error saving chunk: {}", e);
        throw new BadRequestException();
    }
}
 
开发者ID:nus-ncl,项目名称:services-in-one,代码行数:14,代码来源:UploadServiceImpl.java

示例12: encrypt

import org.apache.tomcat.util.codec.binary.Base64; //导入依赖的package包/类
/**
 * 带向量的加密
 * @param str
 * @param secretKey
 * @param iv
 * @return
    * @throws Exception
    */
public static String encrypt(String str, String secretKey, byte[] iv) throws Exception {
	IvParameterSpec zeroIv = new IvParameterSpec(iv);
	SecretKeySpec key = new SecretKeySpec(secretKey.getBytes("UTF-8"), "DES");
	Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
	cipher.init(Cipher.ENCRYPT_MODE, key, zeroIv);
	byte[] encryptedData = cipher.doFinal(str.getBytes("UTF-8"));
	byte[] temp = Base64.encodeBase64(encryptedData, false);
	return new String(temp);
}
 
开发者ID:ggj2010,项目名称:javabase,代码行数:18,代码来源:DesUtil.java

示例13: buildHeaders

import org.apache.tomcat.util.codec.binary.Base64; //导入依赖的package包/类
/**
 * Graylog rest services require authentication - construct an HTTP BASIC Auth header and attach to all outgoing requests
 * Also tell service that JSON is outgoing and is requested for incoming data
 * @return headers
 */
private HttpHeaders buildHeaders() {
    String auth = graylogUsername + ":" + graylogPassword;
    byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(StandardCharsets.US_ASCII) );
    final String authHeader = "Basic " + new String( encodedAuth );

    HttpHeaders headers = new HttpHeaders();
    headers.add(HttpHeaders.AUTHORIZATION, authHeader );
    headers.setContentType(MediaType.APPLICATION_JSON);
    headers.setAccept(Lists.newArrayList(MediaType.APPLICATION_JSON));
    return headers;
}
 
开发者ID:mike-plummer,项目名称:graylog-springboot,代码行数:17,代码来源:GraylogRestInterface.java

示例14: generateSha256

import org.apache.tomcat.util.codec.binary.Base64; //导入依赖的package包/类
public static String generateSha256(String digestStr) throws Exception{
	try{
		MessageDigest digest = MessageDigest.getInstance(HASH_ALGORITHM);
		digest.update(digestStr.getBytes());
		byte[] hash = digest.digest();
		String str = new String(hash);
		return Base64.encodeBase64URLSafeString(hash);
	}
	catch(NoSuchAlgorithmException ex){
		throw new Exception(ex.getMessage());
	}
}
 
开发者ID:ZFGCCP,项目名称:ZFGC3,代码行数:13,代码来源:AuthenticationService.java

示例15: encryptRsa

import org.apache.tomcat.util.codec.binary.Base64; //导入依赖的package包/类
public static String encryptRsa(String digest, Key key){
	try {
		Cipher cipher = Cipher.getInstance("RSA/ECB/NoPadding");
		cipher.init(Cipher.ENCRYPT_MODE, key);
		byte[] cipherData = cipher.doFinal(digest.getBytes("UTF-8"));
		
		return Base64.encodeBase64URLSafeString(cipherData);
	} catch (Exception e) {
		e.printStackTrace();
		return null;
	}
}
 
开发者ID:ZFGCCP,项目名称:ZFGC3,代码行数:13,代码来源:ZfgcSecurityUtils.java


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