Here you can find the source of base64(String string)
static String base64(String string)
//package com.java2s; /*/*from w w w . ja v a 2 s. com*/ * Copyright (c) 2011-2015 The original author or authors * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * and Apache License v2.0 which accompanies this distribution. * * The Eclipse Public License is available at * http://www.eclipse.org/legal/epl-v10.html * * The Apache License v2.0 is available at * http://www.opensource.org/licenses/apache2.0.php * * You may elect to redistribute this code under either of these licenses. */ import java.io.UnsupportedEncodingException; import java.util.Base64; public class Main { static String base64(String string) { try { return Base64.getMimeEncoder().encodeToString(string.getBytes("ISO-8859-1")); } catch (UnsupportedEncodingException e) { // doesn't happen return ""; } } public static String base64(byte[] bytes) { return Base64.getMimeEncoder().encodeToString(bytes); } }