本文整理汇总了Java中org.apache.ws.security.util.Base64.decode方法的典型用法代码示例。如果您正苦于以下问题:Java Base64.decode方法的具体用法?Java Base64.decode怎么用?Java Base64.decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.ws.security.util.Base64
的用法示例。
在下文中一共展示了Base64.decode方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
}
示例2: 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;
}
示例3: 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;
}
示例4: 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);
}
}
示例5: getSalt
import org.apache.ws.security.util.Base64; //导入方法依赖的package包/类
/**
* Get the Salt value of this UsernameToken.
*
* @return Returns the binary Salt value or <code>null</code> if no Salt
* value is available in the username token.
* @throws WSSecurityException
*/
public byte[] getSalt() throws WSSecurityException {
String salt = nodeString(elementSalt);
if (salt != null) {
return Base64.decode(nodeString(elementSalt));
}
return null;
}
示例6: doPasswordDigest
import org.apache.ws.security.util.Base64; //导入方法依赖的package包/类
public static String doPasswordDigest(String nonce, String created, byte[] password) {
String passwdDigest = null;
try {
byte[] b1 = nonce != null ? Base64.decode(nonce) : new byte[0];
byte[] b2 = created != null ? created.getBytes("UTF-8") : new byte[0];
byte[] b3 = password;
byte[] b4 = new byte[b1.length + b2.length + b3.length];
int offset = 0;
System.arraycopy(b1, 0, b4, offset, b1.length);
offset += b1.length;
System.arraycopy(b2, 0, b4, offset, b2.length);
offset += b2.length;
System.arraycopy(b3, 0, b4, offset, b3.length);
MessageDigest sha = MessageDigest.getInstance("SHA-1");
sha.reset();
sha.update(b4);
passwdDigest = Base64.encode(sha.digest());
} catch (Exception e) {
if (DO_DEBUG) {
LOG.debug(e.getMessage(), e);
}
}
return passwdDigest;
}
示例7: getKeyIdentifier
import org.apache.ws.security.util.Base64; //导入方法依赖的package包/类
/**
* Gets the KeyIdentifier.
*
* @return the the X509 certificate or zero if a unknown key identifier type was detected.
*/
public X509Certificate[] getKeyIdentifier(Crypto crypto) throws WSSecurityException {
Element elem = getFirstElement();
String value = elem.getAttribute("ValueType");
String alias = null;
if (X509Security.X509_V3_TYPE.equals(value)) {
X509Security token = new X509Security(elem);
if (token != null) {
X509Certificate cert = token.getX509Certificate(crypto);
X509Certificate[] certs = new X509Certificate[1];
certs[0] = cert;
return certs;
}
} else if (SKI_URI.equals(value)) {
alias = getX509SKIAlias(crypto);
} else if (THUMB_URI.equals(value)) {
Node node = getFirstElement().getFirstChild();
if (node == null) {
return null;
}
if (node.getNodeType() == Node.TEXT_NODE) {
byte[] thumb = Base64.decode(((Text) node).getData());
alias = crypto.getAliasForX509CertThumb(thumb);
}
}
if (alias != null) {
return crypto.getCertificates(alias);
}
return null;
}
示例8: handleToken
import org.apache.ws.security.util.Base64; //导入方法依赖的package包/类
public void handleToken(
Element elem,
Crypto crypto,
Crypto decCrypto,
CallbackHandler cb,
WSDocInfo wsDocInfo,
Vector returnResults,
WSSConfig config
) throws WSSecurityException {
// Deserialize the DKT
dkt = new DerivedKeyToken(elem);
this.extractSecret(wsDocInfo, dkt, cb, crypto);
String tempNonce = dkt.getNonce();
if (tempNonce == null) {
throw new WSSecurityException("Missing wsc:Nonce value");
}
this.nonce = Base64.decode(tempNonce);
this.length = dkt.getLength();
this.label = dkt.getLabel();
this.algorithm = dkt.getAlgorithm();
this.id = dkt.getID();
if (length > 0) {
this.deriveKey();
returnResults.add(
0,
new WSSecurityEngineResult(WSConstants.DKT,
secret,
keyBytes,
id,
null)
);
}
}
示例9: getDecodedBase64EncodedData
import org.apache.ws.security.util.Base64; //导入方法依赖的package包/类
/**
* Method getDecodedBase64EncodedData
*
* @param element
* @return a byte array containing the decoded data
* @throws WSSecurityException
*/
public static byte[] getDecodedBase64EncodedData(Element element) throws WSSecurityException {
StringBuffer sb = new StringBuffer();
NodeList children = element.getChildNodes();
int iMax = children.getLength();
for (int i = 0; i < iMax; i++) {
Node curr = children.item(i);
if (curr.getNodeType() == Node.TEXT_NODE) {
sb.append(((Text) curr).getData());
}
}
String encodedData = sb.toString();
return Base64.decode(encodedData);
}
示例10: testDerivedKeyWithEncodedPasswordBaseline
import org.apache.ws.security.util.Base64; //导入方法依赖的package包/类
/**
* Test for encoded passwords.
*/
public void testDerivedKeyWithEncodedPasswordBaseline() throws Exception {
String password = "password";
// The SHA-1 of the password is known as a password equivalent in the UsernameToken specification.
byte[] passwordHash = MessageDigest.getInstance("SHA-1").digest(password.getBytes("UTF-8"));
byte[] salt = Base64.decode("LKpycbfgRzwDnBz6kkhAAQ==");
int iteration = 1049;
byte[] expectedDerivedKey = Base64.decode("C7Ll/OY4TECb6hZuMMiX/5hzszo=");
byte[] derivedKey = UsernameToken.generateDerivedKey(passwordHash, salt, iteration);
assertTrue("the derived key is not as expected", Arrays.equals(expectedDerivedKey, derivedKey));
}
示例11: getSecretKey
import org.apache.ws.security.util.Base64; //导入方法依赖的package包/类
/**
* Gets the secret key as per WS-Trust spec.
*
* @param keylen How many bytes to generate for the key
* @param labelString the label used to generate the seed
* @return a secret key constructed from information contained in this
* username token
*/
public byte[] getSecretKey(int keylen, String labelString) {
byte[] key = null;
try {
Mac mac = Mac.getInstance("HMACSHA1");
byte[] password;
if (passwordsAreEncoded) {
password = Base64.decode(rawPassword);
} else {
password = rawPassword.getBytes("UTF-8"); // enhancement by Alberto Coletti
}
byte[] label = labelString.getBytes("UTF-8");
byte[] nonce = Base64.decode(getNonce());
byte[] created = getCreated().getBytes("UTF-8");
byte[] seed = new byte[label.length + nonce.length + created.length];
int offset = 0;
System.arraycopy(label, 0, seed, offset, label.length);
offset += label.length;
System.arraycopy(nonce, 0, seed, offset, nonce.length);
offset += nonce.length;
System.arraycopy(created, 0, seed, offset, created.length);
key = P_hash(password, seed, mac, keylen);
if (LOG.isDebugEnabled()) {
LOG.debug("password :" + Base64.encode(password));
LOG.debug("label :" + Base64.encode(label));
LOG.debug("nonce :" + Base64.encode(nonce));
LOG.debug("created :" + Base64.encode(created));
LOG.debug("seed :" + Base64.encode(seed));
LOG.debug("Key :" + Base64.encode(key));
}
} catch (Exception e) {
if (DO_DEBUG) {
LOG.debug(e.getMessage(), e);
}
return null;
}
return key;
}
示例12: decrypt
import org.apache.ws.security.util.Base64; //导入方法依赖的package包/类
/**
* Decrypts a base64 encoded string using the given key (AES 128bit key and
* a Chain Block Cipher)
*
* @param encryptedText
* Base64Encoded String
* @param Secret
* key
* @return
* @throws Exception
*/
public static String decrypt(String encryptedText, String key) throws Exception {
byte[] cipheredBytes = Base64.decode(encryptedText);
byte[] keyBytes = getKeyBytes(key);
return new String(decrypt(cipheredBytes, keyBytes, keyBytes), characterEncoding);
}