當前位置: 首頁>>代碼示例>>Java>>正文


Java Base64.encode方法代碼示例

本文整理匯總了Java中com.sun.org.apache.xml.internal.security.utils.Base64.encode方法的典型用法代碼示例。如果您正苦於以下問題:Java Base64.encode方法的具體用法?Java Base64.encode怎麽用?Java Base64.encode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.sun.org.apache.xml.internal.security.utils.Base64的用法示例。


在下文中一共展示了Base64.encode方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setSignatureValueElement

import com.sun.org.apache.xml.internal.security.utils.Base64; //導入方法依賴的package包/類
/**
 * 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);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:22,代碼來源:XMLSignature.java

示例2: getAsString

import com.sun.org.apache.xml.internal.security.utils.Base64; //導入方法依賴的package包/類
public String getAsString(FacesContext context, UIComponent component, Object value) {
    String retValue = null;

    if ((value != null) && (value instanceof Identifiable)) {
        Identifiable identifiable = (Identifiable) value;
        String className = identifiable.getClass().getName();

        if (identifiable.getId() == null) {
            try {
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                ObjectOutput output = new ObjectOutputStream(bos);
                output.writeObject(identifiable);
                byte[] byteArr = bos.toByteArray();
                String stream = Base64.encode(byteArr);
                retValue = identifiable.getClass().getName() + "_" + stream;
            }
            catch (IOException e) {
                throw new ConverterException("Transient object cannot be output to the stream: " + identifiable.getClass() + ".");
            }
        }
        return retValue;
    }
    throw new ConverterException("Object is null or not implemented Identifiable interface.");
}
 
開發者ID:ddRPB,項目名稱:rpb,代碼行數:25,代碼來源:TransientJsfConverter.java

示例3: setSignatureValueElement

import com.sun.org.apache.xml.internal.security.utils.Base64; //導入方法依賴的package包/類
/**
 * 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);
}
 
開發者ID:openjdk,項目名稱:jdk7-jdk,代碼行數:23,代碼來源:XMLSignature.java

示例4: encryptData

import com.sun.org.apache.xml.internal.security.utils.Base64; //導入方法依賴的package包/類
/**
 * Encrypt some string
 * @param data - non-encrypted string
 * @return - as you expected: encrypted string
 */
public String encryptData(String data) {
    try {
        return Base64.encode(dataEncryptCipher.doFinal(data.getBytes()));
    } catch (Exception e) {
        Main.showError("Cannot encrypt data. How it is can be possible?");
        e.printStackTrace();
        return null;
    }
}
 
開發者ID:Hackness,項目名稱:KeepYourPassword,代碼行數:15,代碼來源:DataManager.java

示例5: DOMCryptoBinary

import com.sun.org.apache.xml.internal.security.utils.Base64; //導入方法依賴的package包/類
/**
 * 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);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:16,代碼來源:DOMCryptoBinary.java

示例6: digest

import com.sun.org.apache.xml.internal.security.utils.Base64; //導入方法依賴的package包/類
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");
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:30,代碼來源:DOMReference.java

示例7: marshalPublicKey

import com.sun.org.apache.xml.internal.security.utils.Base64; //導入方法依賴的package包/類
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);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:35,代碼來源:DOMKeyValue.java

示例8: setDigestValueElement

import com.sun.org.apache.xml.internal.security.utils.Base64; //導入方法依賴的package包/類
/**
 * 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);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:18,代碼來源:Reference.java

示例9: marshalPublicKey

import com.sun.org.apache.xml.internal.security.utils.Base64; //導入方法依賴的package包/類
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 };
    String oid = getCurveOid(ecParams);
    if (oid == null) {
        throw new MarshalException("Invalid ECParameterSpec");
    }
    DOMUtils.setAttribute(namedCurveElem, "URI", "urn:oid:" + oid);
    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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:32,代碼來源:DOMKeyValue.java

示例10: openConnection

import com.sun.org.apache.xml.internal.security.utils.Base64; //導入方法依賴的package包/類
private URLConnection openConnection(URL url) throws IOException {

        String proxyHostProp =
                engineGetProperty(ResolverDirectHTTP.properties[ResolverDirectHTTP.HttpProxyHost]);
        String proxyPortProp =
                engineGetProperty(ResolverDirectHTTP.properties[ResolverDirectHTTP.HttpProxyPort]);
        String proxyUser =
                engineGetProperty(ResolverDirectHTTP.properties[ResolverDirectHTTP.HttpProxyUser]);
        String proxyPass =
                engineGetProperty(ResolverDirectHTTP.properties[ResolverDirectHTTP.HttpProxyPass]);

        Proxy proxy = null;
        if ((proxyHostProp != null) && (proxyPortProp != null)) {
            int port = Integer.parseInt(proxyPortProp);
            proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHostProp, port));
        }

        URLConnection urlConnection;
        if (proxy != null) {
            urlConnection = url.openConnection(proxy);

            if ((proxyUser != null) && (proxyPass != null)) {
                String password = proxyUser + ":" + proxyPass;
                String authString = "Basic " + Base64.encode(password.getBytes("ISO-8859-1"));

                urlConnection.setRequestProperty("Proxy-Authorization", authString);
            }
        } else {
            urlConnection = url.openConnection();
        }

        return urlConnection;
    }
 
開發者ID:campolake,項目名稱:openjdk9,代碼行數:34,代碼來源:ResolverDirectHTTP.java

示例11: encrypt

import com.sun.org.apache.xml.internal.security.utils.Base64; //導入方法依賴的package包/類
private String encrypt(String text, String key) throws Exception {
    byte[] crypted = null;
 try{
   SecretKeySpec skey = new SecretKeySpec(key.getBytes(), "AES");
     Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
     cipher.init(Cipher.ENCRYPT_MODE, skey);
     crypted = cipher.doFinal(text.getBytes());
   }catch(NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException e){

   }
        
   return Base64.encode(crypted);
}
 
開發者ID:wisdomcsharp,項目名稱:SSI_Bitcoin-Storage,代碼行數:14,代碼來源:AES.java

示例12: authenticate

import com.sun.org.apache.xml.internal.security.utils.Base64; //導入方法依賴的package包/類
public int authenticate(String username, String password) {
        String authenStr = username + ":" + password;
        String encodedAuthenStr = Base64.encode(authenStr.getBytes());
        this.connection.setRequestProperty("Authorization", "Basic " + encodedAuthenStr);
        try {
            this.responseCode = this.connection.getResponseCode();
//            this.authenticated = (this.responseCode / 100 == 2);
        } catch (IOException e) {
            // considered as failed
        }
        return this.responseCode;
    }
 
開發者ID:boalang,項目名稱:compiler,代碼行數:13,代碼來源:MetadataLangCacher.java

示例13: authenticate

import com.sun.org.apache.xml.internal.security.utils.Base64; //導入方法依賴的package包/類
public boolean authenticate(String username, String password) {
	String authenStr = username + ":" + password;
	String encodedAuthenStr = Base64.encode(authenStr.getBytes());
	this.connection.setRequestProperty("Authorization", "Basic " + encodedAuthenStr);
	try {
		this.responseCode = this.connection.getResponseCode();
		this.authenticated = (this.responseCode / 100 == 2);
	} catch (IOException e) {
		// considered as failed
	}
	return this.authenticated;
}
 
開發者ID:boalang,項目名稱:compiler,代碼行數:13,代碼來源:MetadataCacher.java

示例14: digest

import com.sun.org.apache.xml.internal.security.utils.Base64; //導入方法依賴的package包/類
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(Level.FINE)) {
        log.log(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(Level.FINE)) {
        log.log(Level.FINE, "Reference digesting completed");
    }
}
 
開發者ID:openjdk,項目名稱:jdk7-jdk,代碼行數:29,代碼來源:DOMReference.java

示例15: setDigestValueElement

import com.sun.org.apache.xml.internal.security.utils.Base64; //導入方法依賴的package包/類
/**
 * 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);
}
 
開發者ID:openjdk,項目名稱:jdk7-jdk,代碼行數:19,代碼來源:Reference.java


注:本文中的com.sun.org.apache.xml.internal.security.utils.Base64.encode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。