Java Code Examples for com.sun.org.apache.xml.internal.security.utils.Base64#encode()
The following examples show how to use
com.sun.org.apache.xml.internal.security.utils.Base64#encode() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XMLSignature.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * Base64 encodes and sets the bytes as the content of the SignatureValue * Node. * * @param bytes bytes to be used by SignatureValue before Base64 encoding */ private void setSignatureValueElement(byte[] bytes) { while (signatureValueElement.hasChildNodes()) { signatureValueElement.removeChild(signatureValueElement.getFirstChild()); } String base64codedValue = Base64.encode(bytes); if (base64codedValue.length() > 76 && !XMLUtils.ignoreLineBreaks()) { base64codedValue = "\n" + base64codedValue + "\n"; } Text t = this.doc.createTextNode(base64codedValue); signatureValueElement.appendChild(t); }
Example 2
Source File: XMLSignature.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Base64 encodes and sets the bytes as the content of the SignatureValue * Node. * * @param bytes bytes to be used by SignatureValue before Base64 encoding */ private void setSignatureValueElement(byte[] bytes) { while (signatureValueElement.hasChildNodes()) { signatureValueElement.removeChild(signatureValueElement.getFirstChild()); } String base64codedValue = Base64.encode(bytes); if (base64codedValue.length() > 76 && !XMLUtils.ignoreLineBreaks()) { base64codedValue = "\n" + base64codedValue + "\n"; } Text t = this.doc.createTextNode(base64codedValue); signatureValueElement.appendChild(t); }
Example 3
Source File: XMLSignature.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
/** * Base64 encodes and sets the bytes as the content of the SignatureValue * Node. * * @param bytes bytes to be used by SignatureValue before Base64 encoding */ private void setSignatureValueElement(byte[] bytes) { while (signatureValueElement.hasChildNodes()) { signatureValueElement.removeChild(signatureValueElement.getFirstChild()); } String base64codedValue = Base64.encode(bytes); if (base64codedValue.length() > 76 && !XMLUtils.ignoreLineBreaks()) { base64codedValue = "\n" + base64codedValue + "\n"; } Text t = this.doc.createTextNode(base64codedValue); signatureValueElement.appendChild(t); }
Example 4
Source File: DOMReference.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public void digest(XMLSignContext signContext) throws XMLSignatureException { Data data = null; if (appliedTransformData == null) { data = dereference(signContext); } else { data = appliedTransformData; } digestValue = transform(data, signContext); // insert digestValue into DigestValue element String encodedDV = Base64.encode(digestValue); if (log.isLoggable(java.util.logging.Level.FINE)) { log.log(java.util.logging.Level.FINE, "Reference object uri = " + uri); } Element digestElem = DOMUtils.getLastChildElement(refElem); if (digestElem == null) { throw new XMLSignatureException("DigestValue element expected"); } DOMUtils.removeAllChildren(digestElem); digestElem.appendChild (refElem.getOwnerDocument().createTextNode(encodedDV)); digested = true; if (log.isLoggable(java.util.logging.Level.FINE)) { log.log(java.util.logging.Level.FINE, "Reference digesting completed"); } }
Example 5
Source File: DOMReference.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
public void digest(XMLSignContext signContext) throws XMLSignatureException { Data data = null; if (appliedTransformData == null) { data = dereference(signContext); } else { data = appliedTransformData; } digestValue = transform(data, signContext); // insert digestValue into DigestValue element String encodedDV = Base64.encode(digestValue); if (log.isLoggable(java.util.logging.Level.FINE)) { log.log(java.util.logging.Level.FINE, "Reference object uri = " + uri); } Element digestElem = DOMUtils.getLastChildElement(refElem); if (digestElem == null) { throw new XMLSignatureException("DigestValue element expected"); } DOMUtils.removeAllChildren(digestElem); digestElem.appendChild (refElem.getOwnerDocument().createTextNode(encodedDV)); digested = true; if (log.isLoggable(java.util.logging.Level.FINE)) { log.log(java.util.logging.Level.FINE, "Reference digesting completed"); } }
Example 6
Source File: Reference.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Method setDigestValueElement * * @param digestValue */ private void setDigestValueElement(byte[] digestValue) { Node n = digestValueElement.getFirstChild(); while (n != null) { digestValueElement.removeChild(n); n = n.getNextSibling(); } String base64codedValue = Base64.encode(digestValue); Text t = this.doc.createTextNode(base64codedValue); digestValueElement.appendChild(t); }
Example 7
Source File: DOMCryptoBinary.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * Create a <code>DOMCryptoBinary</code> instance from the specified * <code>BigInteger</code> * * @param bigNum the arbitrary-length integer * @throws NullPointerException if <code>bigNum</code> is <code>null</code> */ public DOMCryptoBinary(BigInteger bigNum) { if (bigNum == null) { throw new NullPointerException("bigNum is null"); } this.bigNum = bigNum; // convert to bitstring value = Base64.encode(bigNum); }
Example 8
Source File: DOMKeyValue.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
void marshalPublicKey(Node parent, Document doc, String dsPrefix, DOMCryptoContext context) throws MarshalException { String prefix = DOMUtils.getNSPrefix(context, XMLDSIG_11_XMLNS); Element ecKeyValueElem = DOMUtils.createElement(doc, "ECKeyValue", XMLDSIG_11_XMLNS, prefix); Element namedCurveElem = DOMUtils.createElement(doc, "NamedCurve", XMLDSIG_11_XMLNS, prefix); Element publicKeyElem = DOMUtils.createElement(doc, "PublicKey", XMLDSIG_11_XMLNS, prefix); Object[] args = new Object[] { ecParams }; try { String oid = (String) getCurveName.invoke(null, args); DOMUtils.setAttribute(namedCurveElem, "URI", "urn:oid:" + oid); } catch (IllegalAccessException iae) { throw new MarshalException(iae); } catch (InvocationTargetException ite) { throw new MarshalException(ite); } String qname = (prefix == null || prefix.length() == 0) ? "xmlns" : "xmlns:" + prefix; namedCurveElem.setAttributeNS("http://www.w3.org/2000/xmlns/", qname, XMLDSIG_11_XMLNS); ecKeyValueElem.appendChild(namedCurveElem); String encoded = Base64.encode(ecPublicKey); publicKeyElem.appendChild (DOMUtils.getOwnerDocument(publicKeyElem).createTextNode(encoded)); ecKeyValueElem.appendChild(publicKeyElem); parent.appendChild(ecKeyValueElem); }
Example 9
Source File: DOMCryptoBinary.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Create a <code>DOMCryptoBinary</code> instance from the specified * <code>BigInteger</code> * * @param bigNum the arbitrary-length integer * @throws NullPointerException if <code>bigNum</code> is <code>null</code> */ public DOMCryptoBinary(BigInteger bigNum) { if (bigNum == null) { throw new NullPointerException("bigNum is null"); } this.bigNum = bigNum; // convert to bitstring value = Base64.encode(bigNum); }
Example 10
Source File: Reference.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * Method setDigestValueElement * * @param digestValue */ private void setDigestValueElement(byte[] digestValue) { Node n = digestValueElement.getFirstChild(); while (n != null) { digestValueElement.removeChild(n); n = n.getNextSibling(); } String base64codedValue = Base64.encode(digestValue); Text t = this.doc.createTextNode(base64codedValue); digestValueElement.appendChild(t); }
Example 11
Source File: Reference.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** * Method setDigestValueElement * * @param digestValue */ private void setDigestValueElement(byte[] digestValue) { Node n = digestValueElement.getFirstChild(); while (n != null) { digestValueElement.removeChild(n); n = n.getNextSibling(); } String base64codedValue = Base64.encode(digestValue); Text t = this.doc.createTextNode(base64codedValue); digestValueElement.appendChild(t); }
Example 12
Source File: Reference.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * Method setDigestValueElement * * @param digestValue */ private void setDigestValueElement(byte[] digestValue) { Node n = digestValueElement.getFirstChild(); while (n != null) { digestValueElement.removeChild(n); n = n.getNextSibling(); } String base64codedValue = Base64.encode(digestValue); Text t = this.doc.createTextNode(base64codedValue); digestValueElement.appendChild(t); }
Example 13
Source File: DOMCryptoBinary.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
/** * Create a <code>DOMCryptoBinary</code> instance from the specified * <code>BigInteger</code> * * @param bigNum the arbitrary-length integer * @throws NullPointerException if <code>bigNum</code> is <code>null</code> */ public DOMCryptoBinary(BigInteger bigNum) { if (bigNum == null) { throw new NullPointerException("bigNum is null"); } this.bigNum = bigNum; // convert to bitstring value = Base64.encode(bigNum); }
Example 14
Source File: RangerMasterKey.java From ranger with Apache License 2.0 | 5 votes |
private String encryptMasterKey(String password) throws Throwable { if (logger.isDebugEnabled()) { logger.debug("==> RangerMasterKey.encryptMasterKey()"); } Key secretKey = generateMasterKey(); PBEKeySpec pbeKeySpec = getPBEParameterSpec(password); byte[] masterKeyToDB = encryptKey(secretKey.getEncoded(), pbeKeySpec); if (logger.isDebugEnabled()) { logger.debug("<== RangerMasterKey.encryptMasterKey()"); } return Base64.encode(masterKeyToDB); }
Example 15
Source File: DOMCryptoBinary.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * Create a <code>DOMCryptoBinary</code> instance from the specified * <code>BigInteger</code> * * @param bigNum the arbitrary-length integer * @throws NullPointerException if <code>bigNum</code> is <code>null</code> */ public DOMCryptoBinary(BigInteger bigNum) { if (bigNum == null) { throw new NullPointerException("bigNum is null"); } this.bigNum = bigNum; // convert to bitstring value = Base64.encode(bigNum); }
Example 16
Source File: DOMXMLSignature.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
void setValue(byte[] value) { this.value = value; valueBase64 = Base64.encode(value); sigValueElem.appendChild(ownerDoc.createTextNode(valueBase64)); }
Example 17
Source File: DOMXMLSignature.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
void setValue(byte[] value) { this.value = value; valueBase64 = Base64.encode(value); sigValueElem.appendChild(ownerDoc.createTextNode(valueBase64)); }
Example 18
Source File: Signer.java From IDES-Data-Preparation-Java with Creative Commons Zero v1.0 Universal | 4 votes |
public String digest() { if (digest == null) digest = Base64.encode(md.digest()); return digest; }
Example 19
Source File: DOMXMLSignature.java From hottub with GNU General Public License v2.0 | 4 votes |
void setValue(byte[] value) { this.value = value; valueBase64 = Base64.encode(value); sigValueElem.appendChild(ownerDoc.createTextNode(valueBase64)); }
Example 20
Source File: XMLCipher.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
/** * Encrypts a key to an EncryptedKey structure * * @param doc the Context document that will be used to general DOM * @param key Key to encrypt (will use previously set KEK to * perform encryption * @param mgfAlgorithm The xenc11 MGF Algorithm to use * @param oaepParams The OAEPParams to use * @return the <code>EncryptedKey</code> * @throws XMLEncryptionException */ public EncryptedKey encryptKey( Document doc, Key key, String mgfAlgorithm, byte[] oaepParams ) throws XMLEncryptionException { if (log.isLoggable(java.util.logging.Level.FINE)) { log.log(java.util.logging.Level.FINE, "Encrypting key ..."); } if (null == key) { log.log(java.util.logging.Level.SEVERE, "Key unexpectedly null..."); } if (cipherMode != WRAP_MODE) { log.log(java.util.logging.Level.FINE, "XMLCipher unexpectedly not in WRAP_MODE..."); } if (algorithm == null) { throw new XMLEncryptionException("XMLCipher instance without transformation specified"); } contextDocument = doc; byte[] encryptedBytes = null; Cipher c; if (contextCipher == null) { // Now create the working cipher c = constructCipher(algorithm, null); } else { c = contextCipher; } // Now perform the encryption try { // Should internally generate an IV // todo - allow user to set an IV OAEPParameterSpec oaepParameters = constructOAEPParameters( algorithm, digestAlg, mgfAlgorithm, oaepParams ); if (oaepParameters == null) { c.init(Cipher.WRAP_MODE, this.key); } else { c.init(Cipher.WRAP_MODE, this.key, oaepParameters); } encryptedBytes = c.wrap(key); } catch (InvalidKeyException ike) { throw new XMLEncryptionException("empty", ike); } catch (IllegalBlockSizeException ibse) { throw new XMLEncryptionException("empty", ibse); } catch (InvalidAlgorithmParameterException e) { throw new XMLEncryptionException("empty", e); } String base64EncodedEncryptedOctets = Base64.encode(encryptedBytes); if (log.isLoggable(java.util.logging.Level.FINE)) { log.log(java.util.logging.Level.FINE, "Encrypted key octets:\n" + base64EncodedEncryptedOctets); log.log(java.util.logging.Level.FINE, "Encrypted key octets length = " + base64EncodedEncryptedOctets.length()); } CipherValue cv = ek.getCipherData().getCipherValue(); cv.setValue(base64EncodedEncryptedOctets); try { EncryptionMethod method = factory.newEncryptionMethod(new URI(algorithm).toString()); method.setDigestAlgorithm(digestAlg); method.setMGFAlgorithm(mgfAlgorithm); method.setOAEPparams(oaepParams); ek.setEncryptionMethod(method); } catch (URISyntaxException ex) { throw new XMLEncryptionException("empty", ex); } return ek; }