本文整理汇总了Java中org.apache.ws.security.util.Base64类的典型用法代码示例。如果您正苦于以下问题:Java Base64类的具体用法?Java Base64怎么用?Java Base64使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Base64类属于org.apache.ws.security.util包,在下文中一共展示了Base64类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: requestSecurityToken
import org.apache.ws.security.util.Base64; //导入依赖的package包/类
@Override
public SecurityToken requestSecurityToken() throws Exception {
DelegatedKerberosSecurity bst = new DelegatedKerberosSecurity(DOMUtils.createDocument());
bst.retrieveServiceTicket(getContextName(), getServiceName(), getGssCredential());
bst.addWSUNamespace();
bst.setID(wssConfig.getIdAllocator().createSecureId("BST-", bst)); //$NON-NLS-1$
SecurityToken st = new SecurityToken(bst.getID());
st.setToken(bst.getElement());
st.setWsuId(bst.getID());
SecretKey secretKey = bst.getSecretKey();
if (secretKey != null) {
st.setSecret(secretKey.getEncoded());
}
String sha1 = Base64.encode(WSSecurityUtil.generateDigest(bst.getToken()));
st.setSHA1(sha1);
st.setTokenType(bst.getValueType());
return st;
}
示例2: createBSTX509
import org.apache.ws.security.util.Base64; //导入依赖的package包/类
protected static Element createBSTX509(Document doc, X509Certificate cert, Element secRefE)
throws WSSecurityException {
byte data[];
try {
data = cert.getEncoded();
} catch (CertificateEncodingException e) {
throw new WSSecurityException(
WSSecurityException.SECURITY_TOKEN_UNAVAILABLE, "encodeError", null, e
);
}
String prefix = WSSecurityUtil.getPrefixNS(WSConstants.WSSE_NS, secRefE);
Element elem = doc.createElementNS(WSConstants.WSSE_NS, prefix + ":BinarySecurityToken");
WSSecurityUtil.setNamespace(elem, WSConstants.WSSE_NS, prefix);
// elem.setAttributeNS(WSConstants.XMLNS_NS, "xmlns", "");
elem.setAttributeNS(null, "ValueType", X509Security.X509_V3_TYPE);
Text certText = doc.createTextNode(Base64.encode(data)); // no line wrap
elem.appendChild(certText);
return elem;
}
示例3: getToken
import org.apache.ws.security.util.Base64; //导入依赖的package包/类
/**
* get the byte array containing token information.
*
* @return the byte array containing token information
*/
public byte[] getToken() {
Node node = element.getFirstChild();
StringBuffer buffer = new StringBuffer();
while (node != null) {
if (Node.TEXT_NODE == node.getNodeType()) {
buffer.append(((Text)node).getData());
}
node = node.getNextSibling();
}
try {
return Base64.decode(buffer.toString());
} catch (Exception ex) {
if (LOG.isDebugEnabled()) {
LOG.debug(ex.getMessage(), ex);
}
return null;
}
}
示例4: setKeyIdentifierSKI
import org.apache.ws.security.util.Base64; //导入依赖的package包/类
/**
* Sets the KeyIdentifier Element as a X509 Subject-Key-Identifier (SKI). Takes a X509
* certificate, gets it SKI data, converts into base 64 and inserts it into a
* <code>wsse:KeyIdentifier</code> element, which is placed in the
* <code>wsse:SecurityTokenReference</code> element.
*
* @param cert
* is the X509 certificate to get the SKI
* @param crypto
* is the Crypto implementation. Used to read SKI info bytes from certificate
*/
public void setKeyIdentifierSKI(X509Certificate cert, Crypto crypto) throws WSSecurityException {
//
// As per the 1.1 specification, SKI can only be used for a V3 certificate
//
if (cert.getVersion() != 3) {
throw new WSSecurityException(WSSecurityException.UNSUPPORTED_SECURITY_TOKEN,
"invalidCertForSKI", new Object[] { new Integer(cert.getVersion()) });
}
Document doc = this.element.getOwnerDocument();
byte data[] = crypto.getSKIBytesFromCert(cert);
org.w3c.dom.Text text = doc.createTextNode(Base64.encode(data));
createKeyIdentifier(doc, SKI_URI, text, true);
}
示例5: getSKIBytes
import org.apache.ws.security.util.Base64; //导入依赖的package包/类
public byte[] getSKIBytes() {
if (skiBytes != null) {
return skiBytes;
}
Node node = getFirstElement().getFirstChild();
if (node == null) {
return null;
}
if (node.getNodeType() == Node.TEXT_NODE) {
try {
skiBytes = Base64.decode(((Text) node).getData());
} catch (WSSecurityException e) {
return null;
}
}
return skiBytes;
}
示例6: testUsernameTokenDigestText
import org.apache.ws.security.util.Base64; //导入依赖的package包/类
/**
* Test that adds a UserNameToken with a digested password but with type of
* password test.
*/
public void testUsernameTokenDigestText() throws Exception {
WSSecUsernameToken builder = new WSSecUsernameToken();
builder.setPasswordType(WSConstants.PASSWORD_TEXT);
byte[] password = "verySecret".getBytes();
MessageDigest sha = MessageDigest.getInstance("MD5");
sha.reset();
sha.update(password);
String passwdDigest = Base64.encode(sha.digest());
builder.setUserInfo("wernerd", passwdDigest);
LOG.info("Before adding UsernameToken PW Text....");
Document doc = unsignedEnvelope.getAsDocument();
WSSecHeader secHeader = new WSSecHeader();
secHeader.insertSecurityHeader(doc);
Document signedDoc = builder.build(doc, secHeader);
if (LOG.isDebugEnabled()) {
LOG.debug("Message with UserNameToken PW Text:");
String outputString =
org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(signedDoc);
LOG.debug(outputString);
}
}
示例7: encryptAes
import org.apache.ws.security.util.Base64; //导入依赖的package包/类
private static String encryptAes(SecretKey secretKey, String plainData)
{
try {
byte[] b = null;
if (plainData != null) b = plainData.getBytes(MiscUtils.DEFAULT_UTF8_ENCODING);
byte[] encryptedData = encryptDecrypt("AES", Cipher.ENCRYPT_MODE, secretKey, b);
return Base64.encode(encryptedData);
} catch (Exception e) {
logger.error("Cannot encrypt", e);
}
return null;
}
示例8: decryptAes
import org.apache.ws.security.util.Base64; //导入依赖的package包/类
private static String decryptAes(SecretKey secretKey, String encryptedDataStr)
{
try {
byte[] encryptedData = Base64.decode(encryptedDataStr);
byte[] b = encryptDecrypt("AES", Cipher.DECRYPT_MODE, secretKey, encryptedData);
return(new String(b, MiscUtils.DEFAULT_UTF8_ENCODING));
} catch (Exception e) {
logger.error("Cannot decrypt", e);
}
return null;
}
示例9: encrypt
import org.apache.ws.security.util.Base64; //导入依赖的package包/类
String encrypt(String clearText) {
String sha1Hash = null;
try {
MessageDigest md = MessageDigest.getInstance("SHA1"); //$NON-NLS-1$
byte[] digest = md.digest(clearText.getBytes());
sha1Hash = new String(Base64.encode(digest));
} catch (Exception e) {
e.printStackTrace();
}
return sha1Hash;
}
示例10: getSHA1
import org.apache.ws.security.util.Base64; //导入依赖的package包/类
private String getSHA1(byte[] input) throws WSSecurityException {
try {
MessageDigest sha = null;
sha = MessageDigest.getInstance("SHA-1");
sha.reset();
sha.update(input);
byte[] data = sha.digest();
return Base64.encode(data);
} catch (NoSuchAlgorithmException e) {
throw new WSSecurityException(
WSSecurityException.UNSUPPORTED_ALGORITHM, null, null, e
);
}
}
示例11: getSecretKey
import org.apache.ws.security.util.Base64; //导入依赖的package包/类
/**
* Get the derived secret key.
*
* After the <code>prepare()</code> method was called use this method
* to compute a derived secret key. If "useDerivedKey" is set, then the returned secret
* key is derived as per the UsernameToken 1.1 specification. Otherwise, the generation
* of this secret key is according to the WS-Trust specifications.
*
* @return Return the derived secret key of this token or null if <code>prepare()</code>
* was not called before.
*/
public byte[] getSecretKey() throws WSSecurityException {
if (ut == null) {
return null;
}
if (useDerivedKey) {
if (passwordsAreEncoded) {
return UsernameToken.generateDerivedKey(Base64.decode(password), saltValue, iteration);
} else {
return UsernameToken.generateDerivedKey(password, saltValue, iteration);
}
}
return ut.getSecretKey(secretKeyLength);
}
示例12: getDerivedKey
import org.apache.ws.security.util.Base64; //导入依赖的package包/类
/**
* Get the derived key.
*
* After the <code>prepare()</code> method was called use this method
* to compute a derived key. The generation of this secret key is according
* to the UsernameTokenProfile 1.1 specification (section 4 - Key Derivation).
*
* @return Return the derived key of this token or null if <code>prepare()</code>
* was not called before.
*/
public byte[] getDerivedKey() throws WSSecurityException {
if (ut == null || !useDerivedKey) {
return null;
}
if (passwordsAreEncoded) {
return UsernameToken.generateDerivedKey(Base64.decode(password), saltValue, iteration);
} else {
return UsernameToken.generateDerivedKey(password, saltValue, iteration);
}
}
示例13: setToken
import org.apache.ws.security.util.Base64; //导入依赖的package包/类
/**
* set the token information.
*
* @param data
*/
public void setToken(byte[] data) {
if (data == null) {
throw new IllegalArgumentException("data == null");
}
Text node = getFirstNode();
node.setData(Base64.encode(data));
}
示例14: SignatureConfirmation
import org.apache.ws.security.util.Base64; //导入依赖的package包/类
/**
* Constructs a <code>SignatureConfirmation</code> object and parses the
* <code>wsse11:SignatureCOnfirmation</code> element to initialize it.
*
* @param elem the <code>wsse11:SignatureCOnfirmation</code> element that
* contains the confirmation data
*/
public SignatureConfirmation(Element elem) throws WSSecurityException {
element = elem;
String sv = element.getAttributeNS(null, VALUE);
if (sv != null) {
signatureValue = Base64.decode(sv);
}
}
示例15: addNonce
import org.apache.ws.security.util.Base64; //导入依赖的package包/类
/**
* Creates and adds a Nonce element to this UsernameToken
*/
public void addNonce(Document doc) {
if (elementNonce != null) {
return;
}
byte[] nonceValue = new byte[16];
random.nextBytes(nonceValue);
elementNonce = doc.createElementNS(WSConstants.WSSE_NS, "wsse:" + WSConstants.NONCE_LN);
elementNonce.appendChild(doc.createTextNode(Base64.encode(nonceValue)));
elementNonce.setAttributeNS(null, "EncodingType", BASE64_ENCODING);
element.appendChild(elementNonce);
}