public byte[] getTokenValue() { try { return Base64.decode(bst.getValue()); } catch (Base64DecodingException ex) { CRYPTO_IMPL_LOGGER.log(Level.SEVERE,"WSS1209.bst.base64decode.error",ex); return null; } }
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 } }
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"));
private byte[] getDecodedBase64EncodedData(String encodedData) throws XWSSecurityException { try { return Base64.decode(encodedData); } catch (Base64DecodingException e) { log.log(Level.SEVERE, "WSS0144.unableto.decode.base64.data" ,e); throw new SecurityHeaderException( "Unable to decode Base64 encoded data", e); } }
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(); } }
private byte[] getDecodedBase64EncodedData(String encodedData) throws XWSSecurityException { try { return Base64.decode(encodedData); } catch (Base64DecodingException e) { throw new SecurityHeaderException( "Unable to decode Base64 encoded data", e); } }
String s2 = new String(Base64.encode(b1));
/** * Read an PEM encoded X.509v3 certificate * * @param inputString * PEM encoded X.509 certificate * @return certificate */ public BurpCertificate importCertificateFromString(String inputString) { setStatus("Importing certificate..."); CertificateFactory certFactory; try { certFactory = CertificateFactory.getInstance("X.509"); ByteArrayInputStream bais = new ByteArrayInputStream(Base64.decode(inputString)); X509Certificate x509certificate = (X509Certificate) certFactory.generateCertificate(bais); BurpCertificate certificate = new BurpCertificate(x509certificate); certificate.setPublicKey(x509certificate.getPublicKey()); certificate.setSource("Imported"); burpCertificateStore.addCertificate(certificate); setCertificateTree(); setStatus("Certificate imported"); return certificate; } catch (CertificateException | Base64DecodingException e) { setStatus("Error reading input certificate. (" + e.getMessage() + ")"); e.printStackTrace(); } catch (Exception e) { setStatus("Error. (" + e.getMessage() + ")"); e.printStackTrace(); } return null; }
objectOutputStream.writeObject(object); objectOutputStream.close(); encoded = new String(Base64.encode(byteArrayOutputStream.toByteArray())); } catch (IOException e) { e.printStackTrace();
while (it.hasNext()) { X500PrivateCredential cred = (X500PrivateCredential)it.next(); if (matchesKeyIdentifier(Base64.decode(keyIdentifier), cred.getCertificate())) return cred.getPrivateKey();
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));
public PrivateKey getPrivateKey(Map context, byte[] keyIdentifier) throws XWSSecurityException { /* use PrivateKeyCallback */ try { Subject subject = getSubject(context); if (subject != null) { Set set = subject.getPrivateCredentials(X500PrivateCredential.class); if (set != null) { Iterator it = set.iterator(); while (it.hasNext()) { X500PrivateCredential cred = (X500PrivateCredential)it.next(); if (matchesKeyIdentifier(Base64.decode(keyIdentifier), cred.getCertificate())) return cred.getPrivateKey(); } } } PrivateKeyCallback.Request request = new PrivateKeyCallback.SubjectKeyIDRequest( keyIdentifier); PrivateKeyCallback pkCallback = new PrivateKeyCallback(request); Callback[] callbacks = new Callback[] { pkCallback }; _handler.handle(callbacks); return pkCallback.getKey(); } catch (Exception e) { throw new XWSSecurityException(e); } }
while (it.hasNext()) { X500PrivateCredential cred = (X500PrivateCredential)it.next(); if (matchesThumbPrint(Base64.decode(keyIdentifier), cred.getCertificate())) return cred.getPrivateKey();
while (it.hasNext()) { X500PrivateCredential cred = (X500PrivateCredential)it.next(); if (matchesThumbPrint(Base64.decode(keyIdentifier), cred.getCertificate())) return cred.getPrivateKey();