com.sun.org.apache.xml.internal.security.utils.Base64.encode("The string to encode goes here");
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); } }
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 } }
private boolean matchesIssuerSerialAndName( BigInteger serialNumberMatch, String issuerNameMatch, X509Certificate x509Cert) { BigInteger serialNumber = x509Cert.getSerialNumber(); String issuerName = com.sun.org.apache.xml.internal.security.utils.RFC2253Parser.normalize( x509Cert.getIssuerDN().getName()); if (serialNumber.equals(serialNumberMatch) && issuerName.equals(issuerNameMatch)) { return true; } return false; }
private SOAPElement convertToSoapElement(ElementProxy proxy) throws XWSSecurityException { try { Element elem = proxy.getElement(); if (elem instanceof SOAPElement) return (SOAPElement) elem; else return (SOAPElement) document.importNode(elem, true); } catch (Exception e) { log.log( Level.SEVERE, "WSS0321.exception.converting.keyinfo.tosoapelem", e); throw new XWSSecurityException(e); } }
public void writeTo(XMLStreamWriter streamWriter) throws XMLStreamException{ if(nsContext == null){ throw new XMLStreamException("NamespaceContext is null in writeTo method"); } Iterator<NamespaceContextEx.Binding> itr = nsContext.iterator(); stAXC14n.reset(); while(itr.hasNext()){ final NamespaceContextEx.Binding nd = itr.next(); stAXC14n.writeNamespace(nd.getPrefix(),nd.getNamespaceURI()); } DigesterOutputStream dos= null; try{ dos = ref.getDigestOutputStream(); }catch(XMLSignatureException xse){ throw new XMLStreamException(xse); } OutputStream os = new UnsyncBufferedOutputStream(dos); stAXC14n.setStream(os); //EnvelopedTransformWriter etw = new EnvelopedTransformWriter(streamWriter,stAXC14n,ref,jse,dos); ((SecurityElementWriter)she).writeTo(streamWriter); }
cryptoContext = context; try { Node rootNodeOfC14n = XMLUtils.getOwnerDocument(this._xpathNodeSet); this.canonicalizeXPathNodeSet(rootNodeOfC14n,new NameSpaceSymbTable());
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); } }
private boolean matchesIssuerSerialAndName( BigInteger serialNumberMatch, String issuerNameMatch, X509Certificate x509Cert) { BigInteger serialNumber = x509Cert.getSerialNumber(); String issuerName = com.sun.org.apache.xml.internal.security.utils.RFC2253Parser.normalize( x509Cert.getIssuerDN().getName()); if (serialNumber.equals(serialNumberMatch) && issuerName.equals(issuerNameMatch)) { return true; } return false; }
import com.sun.org.apache.xml.internal.security.utils.Base64; String str="Hello World"; String base64_str=Base64.encode(str.getBytes("UTF-8"));
private SOAPElement convertToSoapElement(ElementProxy proxy) throws XWSSecurityException { try { Element elem = proxy.getElement(); if (elem instanceof SOAPElement) { return (SOAPElement) elem; } else { return (SOAPElement) document.importNode(elem, true); } } catch (Exception e) { log.log( Level.SEVERE, "WSS0327.exception.converting.signature.tosoapelement", e); throw new XWSSecurityException(e); } }
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; } }
private boolean matchesIssuerSerialAndName( BigInteger serialNumberMatch, String issuerNameMatch, X509Certificate x509Cert) { BigInteger serialNumber = x509Cert.getSerialNumber(); String issuerName = com.sun.org.apache.xml.internal.security.utils.RFC2253Parser.normalize( x509Cert.getIssuerDN().getName()); if (serialNumber.equals(serialNumberMatch) && issuerName.equals(issuerNameMatch)) { return true; } return false; } }
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(); } }
/** * 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; }
BigInteger serialNo = x509Cert.getSerialNumber(); String currentIssuerName = com.sun.org.apache.xml.internal.security.utils.RFC2253Parser.normalize( x509Cert.getIssuerDN().getName());
objectOutputStream.writeObject(object); objectOutputStream.close(); encoded = new String(Base64.encode(byteArrayOutputStream.toByteArray())); } catch (IOException e) { e.printStackTrace();
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); } }
public X509Certificate getCertificate(Map context, BigInteger serialNumber, String issuerName) throws XWSSecurityRuntimeException { checkEnabled(); try { if (trustStore != null) { Enumeration aliases = trustStore.aliases(); while (aliases.hasMoreElements()) { String alias = (String) aliases.nextElement(); Certificate cert = trustStore.getCertificate(alias); if (cert == null || !"X.509".equals(cert.getType())) { continue; } X509Certificate x509Cert = (X509Certificate) cert; String thisIssuerName = RFC2253Parser.normalize(x509Cert.getIssuerDN().getName()); BigInteger thisSerialNumber = x509Cert.getSerialNumber(); if (thisIssuerName.equals(issuerName) && thisSerialNumber.equals(serialNumber)) { return x509Cert; } } } } catch (KeyStoreException e) { throw new XWSSecurityRuntimeException(e); } throw new XWSSecurityRuntimeException("Certificate key not found"); }
public PrivateKey getPrivateKey(Map context, BigInteger serialNumber, String issuerName) throws XWSSecurityRuntimeException { checkEnabled(); try { Enumeration aliases = keyStore.aliases(); while (aliases.hasMoreElements()) { String alias = (String) aliases.nextElement(); if (!keyStore.isKeyEntry(alias)) { continue; } Certificate cert = keyStore.getCertificate(alias); if (cert == null || !"X.509".equals(cert.getType())) { continue; } X509Certificate x509Cert = (X509Certificate) cert; String thisIssuerName = RFC2253Parser.normalize(x509Cert.getIssuerDN().getName()); BigInteger thisSerialNumber = x509Cert.getSerialNumber(); if (thisIssuerName.equals(issuerName) && thisSerialNumber.equals(serialNumber)) { return (PrivateKey) keyStore.getKey(alias, keyStorePassword); } } } catch (Exception e) { throw new XWSSecurityRuntimeException(e); } throw new XWSSecurityRuntimeException("Private key not found for serial number: " + serialNumber); }