com.sun.org.apache.xml.internal.security.utils.Base64.encode("The string to encode goes here");
import com.sun.org.apache.xml.internal.security.utils.Base64; String str="Hello World"; String base64_str=Base64.encode(str.getBytes("UTF-8"));
import com.sun.org.apache.xml.internal.security.exceptions.Base64DecodingException; import com.sun.org.apache.xml.internal.security.utils.Base64; import java.io.IOException; public class Base64Test { public static void main(String args[]) throws IOException, Base64DecodingException { String orig = "original String before base64 encoding in Java"; //encoding byte array into base 64 String encoded = Base64.encode(orig.getBytes("UTF-8"));//make sure the bytes are utf-8 and not platform default System.out.println("Original String: " + orig ); System.out.println("Base64 Encoded String : " + new String(encoded,"UTF-8"));//ensure string is utf-8 //decoding byte array into base64 byte[] decoded = Base64.decode(encoded); System.out.println("Base 64 Decoded String : " + new String(decoded,"UTF-8"));//ensure string is utf-8 } }
public static String serializeObjectToString(Object p_value) { if ((p_value instanceof java.util.Date)) { String dateString = p_value.toString(); if ((p_value instanceof java.sql.Date)) { dateString = dateString + " 00:00:00.000000"; } else if ((p_value instanceof Time)) { dateString = "1900-01-01 " + dateString + ".000000"; } else if (((p_value instanceof Timestamp)) && (dateString.length() < "yyyy-MM-dd HH:mm:ss.SSSSSS".length())) { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); dateString = df.format(p_value) + "000"; } return dateString.replace(" ", "T"); }if ((p_value instanceof byte[])) { return com.sun.org.apache.xml.internal.security.utils.Base64.encode((byte[])p_value); //return new String(Base64.encode((byte[])p_value)); } return p_value.toString(); } }
String s2 = new String(Base64.encode(b1));
objectOutputStream.writeObject(object); objectOutputStream.close(); encoded = new String(Base64.encode(byteArrayOutputStream.toByteArray())); } catch (IOException e) { e.printStackTrace();
return Base64.encode(encrypt(plaintext, passphrase, salt));
md.update( password.getBytes() ); byte[] encodedPassword = md.digest(); encoded = Base64.encode(encodedPassword); } catch (NoSuchAlgorithmException ex) { usernameToken.addChildElement("Nonce", "wsse"); nonce.setAttribute("EncodingType", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"); nonce.addTextNode(Base64.encode(nonceBytes));