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


Java Base64.decodeBase64方法代码示例

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


在下文中一共展示了Base64.decodeBase64方法的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: 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

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

示例4: stringToRsaKey

import org.apache.tomcat.util.codec.binary.Base64; //导入方法依赖的package包/类
public static Key stringToRsaKey(String key) throws NoSuchAlgorithmException, InvalidKeySpecException{
	try {
		byte [] keyByte = Base64.decodeBase64(key.getBytes("UTF-8"));
		KeyFactory fact = KeyFactory.getInstance("RSA");
		
		return fact.generatePublic(new X509EncodedKeySpec(keyByte));
	} catch (UnsupportedEncodingException e) {
		e.printStackTrace();
		return null;
	}
}
 
开发者ID:ZFGCCP,项目名称:ZFGC3,代码行数:12,代码来源:ZfgcSecurityUtils.java

示例5: stringToRsaPrivKey

import org.apache.tomcat.util.codec.binary.Base64; //导入方法依赖的package包/类
public static Key stringToRsaPrivKey(String key) throws InvalidKeySpecException, NoSuchAlgorithmException{
	try {
		byte [] keyByte = Base64.decodeBase64(key.getBytes("UTF-8"));
		KeyFactory fact = KeyFactory.getInstance("RSA");
		
		return fact.generatePrivate(new PKCS8EncodedKeySpec(keyByte));
	} catch (UnsupportedEncodingException e) {
		e.printStackTrace();
		return null;
	}
}
 
开发者ID:ZFGCCP,项目名称:ZFGC3,代码行数:12,代码来源:ZfgcSecurityUtils.java

示例6: getResourceAsStream

import org.apache.tomcat.util.codec.binary.Base64; //导入方法依赖的package包/类
private static InputStream getResourceAsStream(String fileContent) {
    byte[] decoded = Base64.decodeBase64(fileContent);
    return new ByteArrayInputStream(decoded);
}
 
开发者ID:thingsboard,项目名称:thingsboard-gateway,代码行数:5,代码来源:ConfigurationTools.java

示例7: codeToKey

import org.apache.tomcat.util.codec.binary.Base64; //导入方法依赖的package包/类
public static Key codeToKey(String key) throws Exception {
    byte[] keyBytes = Base64.decodeBase64(key);
    SecretKeySpec secretKey = new SecretKeySpec(keyBytes, KEY_ALGORITHM);
    return secretKey;
}
 
开发者ID:codedrinker,项目名称:commenthub,代码行数:6,代码来源:AESSecurityUtil.java

示例8: decodeWord

import org.apache.tomcat.util.codec.binary.Base64; //导入方法依赖的package包/类
/**
 * Parse a string using the RFC 2047 rules for an "encoded-word"
 * type.  This encoding has the syntax:
 *
 * encoded-word = "=?" charset "?" encoding "?" encoded-text "?="
 *
 * @param word   The possibly encoded word value.
 *
 * @return The decoded word.
 * @throws ParseException
 * @throws UnsupportedEncodingException
 */
private static String decodeWord(String word) throws ParseException, UnsupportedEncodingException {
    // encoded words start with the characters "=?".  If this not an encoded word, we throw a
    // ParseException for the caller.

    if (!word.startsWith(ENCODED_TOKEN_MARKER)) {
        throw new ParseException("Invalid RFC 2047 encoded-word: " + word);
    }

    int charsetPos = word.indexOf('?', 2);
    if (charsetPos == -1) {
        throw new ParseException("Missing charset in RFC 2047 encoded-word: " + word);
    }

    // pull out the character set information (this is the MIME name at this point).
    String charset = word.substring(2, charsetPos).toLowerCase(Locale.ENGLISH);

    // now pull out the encoding token the same way.
    int encodingPos = word.indexOf('?', charsetPos + 1);
    if (encodingPos == -1) {
        throw new ParseException("Missing encoding in RFC 2047 encoded-word: " + word);
    }

    String encoding = word.substring(charsetPos + 1, encodingPos);

    // and finally the encoded text.
    int encodedTextPos = word.indexOf(ENCODED_TOKEN_FINISHER, encodingPos + 1);
    if (encodedTextPos == -1) {
        throw new ParseException("Missing encoded text in RFC 2047 encoded-word: " + word);
    }

    String encodedText = word.substring(encodingPos + 1, encodedTextPos);

    // seems a bit silly to encode a null string, but easy to deal with.
    if (encodedText.length() == 0) {
        return "";
    }

    try {
        // the decoder writes directly to an output stream.
        ByteArrayOutputStream out = new ByteArrayOutputStream(encodedText.length());

        byte[] decodedData;
        // Base64 encoded?
        if (encoding.equals(BASE64_ENCODING_MARKER)) {
            decodedData = Base64.decodeBase64(encodedText);
        } else if (encoding.equals(QUOTEDPRINTABLE_ENCODING_MARKER)) { // maybe quoted printable.
            byte[] encodedData = encodedText.getBytes(US_ASCII_CHARSET);
            QuotedPrintableDecoder.decode(encodedData, out);
            decodedData = out.toByteArray();
        } else {
            throw new UnsupportedEncodingException("Unknown RFC 2047 encoding: " + encoding);
        }
        // Convert decoded byte data into a string.
        return new String(decodedData, javaCharset(charset));
    } catch (IOException e) {
        throw new UnsupportedEncodingException("Invalid RFC 2047 encoding");
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:71,代码来源:MimeUtility.java

示例9: doGet

import org.apache.tomcat.util.codec.binary.Base64; //导入方法依赖的package包/类
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
	DB dbProperties = new DB(getServletContext().getInitParameter("dbHost"), getServletContext().getInitParameter("dbPort"), getServletContext().getInitParameter("dbName"), getServletContext().getInitParameter("dbUser"), getServletContext().getInitParameter("dbPassword"));
   			
	PrintWriter out = response.getWriter();
	String authHeader = request.getHeader("authorization");
	String encodedValue = authHeader.split(" ")[1];
	byte[] decoded = Base64.decodeBase64(encodedValue);
	String decodedValue =  new String(decoded, StandardCharsets.UTF_8);
	DynUser current = LoginDao.validate( decodedValue.split(":")[0], decodedValue.split(":")[1], request, dbProperties);
	
	if ( current != null ) {
		String myip = request.getParameter("myip");
		if (myip == null) {
			myip = request.getHeader("X-FORWARDED-FOR");   
			if(myip==null)	{
			    myip = request.getRemoteAddr();
			}
		}
		if (isValidInetAddress(myip)) {
			String hostname = request.getParameter("hostname");
			List<String> hostnames;
			hostnames = Arrays.asList(hostname.split("\\s*,\\s*"));
			ArrayList<String> hostlist = new ArrayList<String>(hostnames); 
			if (hostlist.size() < 11) {  // 10 or less hosts as 10 is max for users
				
				ArrayList<Integer> hostID = UpdateDao.checkHosts(hostlist, current, dbProperties);
				if (hostID != null) {
					if (!UpdateDao.isTheSame(myip, hostlist, current, dbProperties)) {
						//update records
						UpdateDao.updateAddress(myip, hostID, dbProperties);
						UpdateDao.updateDNSAddress(myip, hostID, dbProperties);
						out.println("good");
						out.println(myip);
					} else {
						// no change needed.
						out.println("nochg");
					}
					
				} else {
					out.println("nohost");
				}
				
			} else {
				out.println("numhost");
			}
			
		} else {
			out.println("badaddress");
		}
	} else {
		out.println("badauth");
	}
}
 
开发者ID:CanadianRepublican,项目名称:DDNS_Server,代码行数:55,代码来源:UpdateServlet.java

示例10: authenticate

import org.apache.tomcat.util.codec.binary.Base64; //导入方法依赖的package包/类
/**
 * Authenticate the user making this request, based on the specified login
 * configuration. Return <code>true</code> if any specified constraint has
 * been satisfied, or <code>false</code> if we have created a response
 * challenge already.
 *
 * @param request
 *            Request we are processing
 * @param response
 *            Response we are creating
 * @param config
 *            Login configuration describing how authentication should be
 *            performed
 *
 * @exception IOException
 *                if an input/output error occurs
 */
@Override
public boolean authenticate(Request request, HttpServletResponse response, LoginConfig config) throws IOException {

	if (checkForCachedAuthentication(request, response, true)) {
		return true;
	}

	// Validate any credentials already included with this request
	String username = null;
	String password = null;

	MessageBytes authorization = request.getCoyoteRequest().getMimeHeaders().getValue("authorization");

	if (authorization != null) {
		authorization.toBytes();
		ByteChunk authorizationBC = authorization.getByteChunk();
		if (authorizationBC.startsWithIgnoreCase("basic ", 0)) {
			authorizationBC.setOffset(authorizationBC.getOffset() + 6);

			byte[] decoded = Base64.decodeBase64(authorizationBC.getBuffer(), authorizationBC.getOffset(),
					authorizationBC.getLength());

			// Get username and password
			int colon = -1;
			for (int i = 0; i < decoded.length; i++) {
				if (decoded[i] == ':') {
					colon = i;
					break;
				}
			}

			if (colon < 0) {
				username = new String(decoded, B2CConverter.ISO_8859_1);
			} else {
				username = new String(decoded, 0, colon, B2CConverter.ISO_8859_1);
				password = new String(decoded, colon + 1, decoded.length - colon - 1, B2CConverter.ISO_8859_1);
			}

			authorizationBC.setOffset(authorizationBC.getOffset() - 6);
		}

		Principal principal = context.getRealm().authenticate(username, password);
		if (principal != null) {
			register(request, response, principal, HttpServletRequest.BASIC_AUTH, username, password);
			return (true);
		}
	}

	StringBuilder value = new StringBuilder(16);
	value.append("Basic realm=\"");
	if (config.getRealmName() == null) {
		value.append(REALM_NAME);
	} else {
		value.append(config.getRealmName());
	}
	value.append('\"');
	response.setHeader(AUTH_HEADER_NAME, value.toString());
	response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
	return (false);

}
 
开发者ID:how2j,项目名称:lazycat,代码行数:79,代码来源:BasicAuthenticator.java

示例11: decodeWord

import org.apache.tomcat.util.codec.binary.Base64; //导入方法依赖的package包/类
/**
 * Parse a string using the RFC 2047 rules for an "encoded-word" type. This
 * encoding has the syntax:
 *
 * encoded-word = "=?" charset "?" encoding "?" encoded-text "?="
 *
 * @param word
 *            The possibly encoded word value.
 *
 * @return The decoded word.
 * @throws ParseException
 * @throws UnsupportedEncodingException
 */
private static String decodeWord(String word) throws ParseException, UnsupportedEncodingException {
	// encoded words start with the characters "=?". If this not an encoded
	// word, we throw a
	// ParseException for the caller.

	if (!word.startsWith(ENCODED_TOKEN_MARKER)) {
		throw new ParseException("Invalid RFC 2047 encoded-word: " + word);
	}

	int charsetPos = word.indexOf('?', 2);
	if (charsetPos == -1) {
		throw new ParseException("Missing charset in RFC 2047 encoded-word: " + word);
	}

	// pull out the character set information (this is the MIME name at this
	// point).
	String charset = word.substring(2, charsetPos).toLowerCase(Locale.ENGLISH);

	// now pull out the encoding token the same way.
	int encodingPos = word.indexOf('?', charsetPos + 1);
	if (encodingPos == -1) {
		throw new ParseException("Missing encoding in RFC 2047 encoded-word: " + word);
	}

	String encoding = word.substring(charsetPos + 1, encodingPos);

	// and finally the encoded text.
	int encodedTextPos = word.indexOf(ENCODED_TOKEN_FINISHER, encodingPos + 1);
	if (encodedTextPos == -1) {
		throw new ParseException("Missing encoded text in RFC 2047 encoded-word: " + word);
	}

	String encodedText = word.substring(encodingPos + 1, encodedTextPos);

	// seems a bit silly to encode a null string, but easy to deal with.
	if (encodedText.length() == 0) {
		return "";
	}

	try {
		// the decoder writes directly to an output stream.
		ByteArrayOutputStream out = new ByteArrayOutputStream(encodedText.length());

		byte[] decodedData;
		// Base64 encoded?
		if (encoding.equals(BASE64_ENCODING_MARKER)) {
			decodedData = Base64.decodeBase64(encodedText);
		} else if (encoding.equals(QUOTEDPRINTABLE_ENCODING_MARKER)) { // maybe
																		// quoted
																		// printable.
			byte[] encodedData = encodedText.getBytes(US_ASCII_CHARSET);
			QuotedPrintableDecoder.decode(encodedData, out);
			decodedData = out.toByteArray();
		} else {
			throw new UnsupportedEncodingException("Unknown RFC 2047 encoding: " + encoding);
		}
		// Convert decoded byte data into a string.
		return new String(decodedData, javaCharset(charset));
	} catch (IOException e) {
		throw new UnsupportedEncodingException("Invalid RFC 2047 encoding");
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:76,代码来源:MimeUtility.java

示例12: verifyEmail

import org.apache.tomcat.util.codec.binary.Base64; //导入方法依赖的package包/类
@PutMapping(path = "/users/{id}/emails/{emailBase64}", consumes = MediaType.APPLICATION_JSON_VALUE)
public boolean verifyEmail(@PathVariable String id, @PathVariable String emailBase64, @RequestBody VerificationKeyInfo keyInfo) {
    final String email = new String(Base64.decodeBase64(emailBase64));
    return registrationService.verifyEmail(id, email, keyInfo.getKey());
}
 
开发者ID:nus-ncl,项目名称:services-in-one,代码行数:6,代码来源:RegistrationController.java

示例13: sendEmail

import org.apache.tomcat.util.codec.binary.Base64; //导入方法依赖的package包/类
public void sendEmail(String html, List<Attachment> attachments, InternetAddress recipient, String title)
        throws MessagingException, UnsupportedEncodingException {
    Properties properties = new Properties();
    properties.put("mail.smtp.host", smtpHost);
    properties.put("mail.smtp.port", smtpPort);
    properties.put("mail.smtp.auth", smtpAuth);
    properties.put("mail.smtp.starttls.enable", smtpStarttls);
    properties.put("mail.user", userName);
    properties.put("mail.password", password);

    Authenticator auth = new Authenticator() {
        public PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(userName, password);
        }
    };

    Session session = Session.getInstance(properties, auth);

    Message msg = new MimeMessage(session);

    msg.setFrom(new InternetAddress(mailFrom, mailFromName));

    InternetAddress[] toAddresses = { recipient };

    msg.setRecipients(Message.RecipientType.TO, toAddresses);
    msg.setSubject(javax.mail.internet.MimeUtility.encodeText(title, "UTF-8", "Q"));
    msg.setSentDate(new Date());

    MimeBodyPart wrap = new MimeBodyPart();

    MimeMultipart cover = new MimeMultipart("alternative");

    MimeBodyPart htmlContent = new MimeBodyPart();
    MimeBodyPart textContent = new MimeBodyPart();
    cover.addBodyPart(textContent);
    cover.addBodyPart(htmlContent);

    wrap.setContent(cover);

    MimeMultipart content = new MimeMultipart("related");
    content.addBodyPart(wrap);

    for (Attachment attachment : attachments) {
        ByteArrayDataSource dSource = new ByteArrayDataSource(Base64.decodeBase64(attachment.getBase64Image()),
                attachment.getMimeType());
        MimeBodyPart filePart = new MimeBodyPart();
        filePart.setDataHandler(new DataHandler(dSource));
        filePart.setFileName(attachment.getFileName());
        filePart.setHeader("Content-ID", "<" + attachment.getCid() + ">");
        filePart.setDisposition(MimeBodyPart.INLINE);
        content.addBodyPart(filePart);
    }

    htmlContent.setContent(html, "text/html; charset=UTF-8");
    textContent.setContent(
            "Twoj klient poczty nie wspiera formatu HTML/Your e-mail client doesn't support HTML format.",
            "text/plain; charset=UTF-8");

    msg.setContent(content);

    Transport.send(msg);
}
 
开发者ID:filipcynarski,项目名称:EMailSenderService,代码行数:63,代码来源:EmailMessage.java

示例14: convertToByteArray

import org.apache.tomcat.util.codec.binary.Base64; //导入方法依赖的package包/类
private byte[] convertToByteArray(String text) {
    return Base64.decodeBase64(text);
}
 
开发者ID:ThoughtWorksInc,项目名称:hackerbrasileiro,代码行数:4,代码来源:Photos.java

示例15: decodeWord

import org.apache.tomcat.util.codec.binary.Base64; //导入方法依赖的package包/类
/**
 * Parse a string using the RFC 2047 rules for an "encoded-word"
 * type.  This encoding has the syntax:
 *
 * encoded-word = "=?" charset "?" encoding "?" encoded-text "?="
 *
 * @param word   The possibly encoded word value.
 *
 * @return The decoded word.
 * @throws ParseException
 * @throws UnsupportedEncodingException
 */
private static String decodeWord(String word) throws ParseException, UnsupportedEncodingException {
    // encoded words start with the characters "=?".  If this not an encoded word, we throw a
    // ParseException for the caller.

    if (!word.startsWith(ENCODED_TOKEN_MARKER)) {
        throw new ParseException("Invalid RFC 2047 encoded-word: " + word);
    }

    int charsetPos = word.indexOf('?', 2);
    if (charsetPos == -1) {
        throw new ParseException("Missing charset in RFC 2047 encoded-word: " + word);
    }

    // pull out the character set information (this is the MIME name at this point).
    String charset = word.substring(2, charsetPos).toLowerCase();

    // now pull out the encoding token the same way.
    int encodingPos = word.indexOf('?', charsetPos + 1);
    if (encodingPos == -1) {
        throw new ParseException("Missing encoding in RFC 2047 encoded-word: " + word);
    }

    String encoding = word.substring(charsetPos + 1, encodingPos);

    // and finally the encoded text.
    int encodedTextPos = word.indexOf(ENCODED_TOKEN_FINISHER, encodingPos + 1);
    if (encodedTextPos == -1) {
        throw new ParseException("Missing encoded text in RFC 2047 encoded-word: " + word);
    }

    String encodedText = word.substring(encodingPos + 1, encodedTextPos);

    // seems a bit silly to encode a null string, but easy to deal with.
    if (encodedText.length() == 0) {
        return "";
    }

    try {
        // the decoder writes directly to an output stream.
        ByteArrayOutputStream out = new ByteArrayOutputStream(encodedText.length());

        byte[] decodedData;
        // Base64 encoded?
        if (encoding.equals(BASE64_ENCODING_MARKER)) {
            decodedData = Base64.decodeBase64(encodedText);
        } else if (encoding.equals(QUOTEDPRINTABLE_ENCODING_MARKER)) { // maybe quoted printable.
            byte[] encodedData = encodedText.getBytes(US_ASCII_CHARSET);
            QuotedPrintableDecoder.decode(encodedData, out);
            decodedData = out.toByteArray();
        } else {
            throw new UnsupportedEncodingException("Unknown RFC 2047 encoding: " + encoding);
        }
        // Convert decoded byte data into a string.
        return new String(decodedData, javaCharset(charset));
    } catch (IOException e) {
        throw new UnsupportedEncodingException("Invalid RFC 2047 encoding");
    }
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:71,代码来源:MimeUtility.java


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