本文整理匯總了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);
}
示例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.");
}
示例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);
}
示例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;
}
}
示例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);
}
示例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");
}
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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");
}
}
示例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);
}