本文整理了Java中org.apache.xml.security.utils.Base64
类的一些代码示例,展示了Base64
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Base64
类的具体详情如下:
包路径:org.apache.xml.security.utils.Base64
类名称:Base64
[英]Implementation of MIME's Base64 encoding and decoding conversions. Optimized code. (raw version taken from oreilly.jonathan.util, and currently org.apache.xerces.ds.util.Base64)
[中]MIME的Base64编码和解码转换的实现。优化代码。(原始版本取自oreilly.jonathan.util,当前为org.apache.xerces.ds.util.Base64)
代码示例来源:origin: org.apache.santuario/xmlsec
/**
* Encode a byte array and fold lines at the standard 76th character unless
* ignore line breaks property is set.
*
* @param binaryData <code>byte[]</code> to be base64 encoded
* @return the <code>String</code> with encoded data
*/
public static final String encode(byte[] binaryData) {
return XMLUtils.ignoreLineBreaks()
? encode(binaryData, Integer.MAX_VALUE)
: encode(binaryData, BASE64DEFAULTLENGTH);
}
代码示例来源:origin: org.apache.santuario/xmlsec
/**
* Decodes Base64 data into outputstream
*
* @param base64Data Byte array containing Base64 data
* @param os the outputstream
* @throws IOException
* @throws Base64DecodingException
*/
public static final void decode(byte[] base64Data, OutputStream os)
throws Base64DecodingException, IOException {
decode(base64Data, os, -1);
}
代码示例来源:origin: org.apache.santuario/xmlsec
/**
* Encode in Base64 the given <code>{@link BigInteger}</code>.
*
* @param big
* @return String with Base64 encoding
*/
public static final String encode(BigInteger big) {
return encode(getBytes(big, big.bitLength()));
}
代码示例来源:origin: org.apache.santuario/xmlsec
/**
* Decodes Base64 data into outputstream
*
* @param base64Data String containing Base64 data
* @param os the outputstream
* @throws IOException
* @throws Base64DecodingException
*/
public static final void decode(String base64Data, OutputStream os)
throws Base64DecodingException, IOException {
byte[] bytes = new byte[base64Data.length()];
int len = getBytesInternal(base64Data, bytes);
decode(bytes, os, len);
}
代码示例来源:origin: org.wso2.carbon.identity/org.wso2.carbon.identity.relyingparty
certInBytes = Base64.decode(certValue);
inputStream = new ByteArrayInputStream(certInBytes);
factory = CertificateFactory.getInstance("X509");
modElem = (Element) omElem.getFirstChildWithName(Modulus.DEFAULT_ELEMENT_NAME);
expElem = (Element) omElem.getFirstChildWithName(Exponent.DEFAULT_ELEMENT_NAME);
mod = Base64.decodeBigIntegerFromElement(modElem);
exp = Base64.decodeBigIntegerFromElement(expElem);
} else {
exp = DEFAULT_EXPONENET;
代码示例来源:origin: org.wso2.carbon.identity/org.wso2.carbon.identity.core
public static String getHMAC(String secretKey, String baseString) throws SignatureException {
try {
SecretKeySpec key = new SecretKeySpec(secretKey.getBytes(), HMAC_SHA1_ALGORITHM);
Mac mac = Mac.getInstance(HMAC_SHA1_ALGORITHM);
mac.init(key);
byte[] rawHmac = mac.doFinal(baseString.getBytes());
return Base64.encode(rawHmac);
} catch (Exception e) {
throw new SignatureException("Failed to generate HMAC : " + e.getMessage());
}
}
代码示例来源:origin: org.apache.santuario/xmlsec
/**
* Decode a base 64 string into a {@link BigInteger}
* @param base64str Base 64 encoded string.
* @return a decoded BigInteger
* @throws Base64DecodingException
*/
public static BigInteger decodeBigIntegerFromString(String base64str)
throws Base64DecodingException {
return new BigInteger(1, Base64.decode(base64str));
}
代码示例来源:origin: org.wso2.carbon.identity.framework/org.wso2.carbon.identity.core
public static String getHMAC(String secretKey, String baseString) throws SignatureException {
try {
SecretKeySpec key = new SecretKeySpec(secretKey.getBytes(), HMAC_SHA1_ALGORITHM);
Mac mac = Mac.getInstance(HMAC_SHA1_ALGORITHM);
mac.init(key);
byte[] rawHmac = mac.doFinal(baseString.getBytes());
return Base64.encode(rawHmac);
} catch (Exception e) {
throw new SignatureException("Failed to generate HMAC : " + e.getMessage());
}
}
代码示例来源:origin: org.apache.santuario/xmlsec
/**
* Method decodeBigIntegerFromElement
*
* @param element
* @return the biginteger obtained from the node
* @throws Base64DecodingException
*/
public static final BigInteger decodeBigIntegerFromElement(Element element)
throws Base64DecodingException {
return new BigInteger(1, Base64.decode(element));
}
代码示例来源:origin: pl.edu.icm.yadda/yadda-model
/**
* Encode a native Java BigInteger type to a base64-encoded ds:CryptoBinary value.
*
* @param bigInt the BigInteger value
* @return the encoded CryptoBinary value
*/
public static final String encodeCryptoBinaryFromBigInteger(BigInteger bigInt) {
// This code is really complicated, for now just use the Apache xmlsec lib code directly.
byte[] bigIntBytes = org.apache.xml.security.utils.Base64.encode(bigInt, bigInt.bitLength());
return Base64.encodeBytes(bigIntBytes);
}
代码示例来源:origin: org.wso2.carbon.identity/org.wso2.carbon.identity.core
public static String getPPIDDisplayValue(String value) throws Exception {
log.info("Generating display value of PPID : " + value);
byte[] rawPpid = Base64.decode(value);
MessageDigest sha1 = MessageDigest.getInstance("SHA1");
sha1.update(rawPpid);
byte[] hashId = sha1.digest();
char[] returnChars = new char[10];
for (int i = 0; i < 10; i++) {
int rawValue = (hashId[i] + 128) % 32;
returnChars[i] = ppidDisplayCharMap[rawValue];
}
StringBuilder sb = new StringBuilder();
sb.append(returnChars, 0, 3);
sb.append("-");
sb.append(returnChars, 3, 4);
sb.append("-");
sb.append(returnChars, 6, 3);
return sb.toString();
}
代码示例来源:origin: org.opensaml/xmltooling
/**
* Encode a native Java BigInteger type to a base64-encoded ds:CryptoBinary value.
*
* @param bigInt the BigInteger value
* @return the encoded CryptoBinary value
*/
public static final String encodeCryptoBinaryFromBigInteger(BigInteger bigInt) {
// This code is really complicated, for now just use the Apache xmlsec lib code directly.
byte[] bigIntBytes = org.apache.xml.security.utils.Base64.encode(bigInt, bigInt.bitLength());
return Base64.encodeBytes(bigIntBytes);
}
代码示例来源:origin: org.apache.santuario/xmlsec
/**
* Method decode
*
* Takes the <CODE>Text</CODE> children of the Element and interprets
* them as input for the <CODE>Base64.decode()</CODE> function.
*
* @param element
* @return the byte obtained of the decoding the element
* $todo$ not tested yet
* @throws Base64DecodingException
*/
public static final byte[] decode(Element element) throws Base64DecodingException {
Node sibling = element.getFirstChild();
StringBuilder sb = new StringBuilder();
while (sibling != null) {
if (sibling.getNodeType() == Node.TEXT_NODE) {
Text t = (Text) sibling;
sb.append(t.getData());
}
sibling = sibling.getNextSibling();
}
return decode(sb.toString());
}
代码示例来源:origin: io.apigee.opensaml/xmltooling
/**
* Encode a native Java BigInteger type to a base64-encoded ds:CryptoBinary value.
*
* @param bigInt the BigInteger value
* @return the encoded CryptoBinary value
*/
public static final String encodeCryptoBinaryFromBigInteger(BigInteger bigInt) {
// This code is really complicated, for now just use the Apache xmlsec lib code directly.
byte[] bigIntBytes = org.apache.xml.security.utils.Base64.encode(bigInt, bigInt.bitLength());
return Base64.encodeBytes(bigIntBytes);
}
代码示例来源:origin: org.wso2.carbon.identity.framework/org.wso2.carbon.identity.core
public static String getPPIDDisplayValue(String value) throws Exception {
if (log.isDebugEnabled()) {
log.debug("Generating display value of PPID : " + value);
}
byte[] rawPpid = Base64.decode(value);
MessageDigest sha1 = MessageDigest.getInstance("SHA1");
sha1.update(rawPpid);
byte[] hashId = sha1.digest();
char[] returnChars = new char[10];
for (int i = 0; i < 10; i++) {
int rawValue = (hashId[i] + 128) % 32;
returnChars[i] = ppidDisplayCharMap[rawValue];
}
StringBuilder sb = new StringBuilder();
sb.append(returnChars, 0, 3);
sb.append("-");
sb.append(returnChars, 3, 4);
sb.append("-");
sb.append(returnChars, 6, 3);
return sb.toString();
}
代码示例来源:origin: Evolveum/midpoint
private String getSecretKeyDigest(SecretKey key) throws NinjaException {
MessageDigest sha1;
try {
sha1 = MessageDigest.getInstance(KEY_DIGEST_TYPE);
} catch (NoSuchAlgorithmException ex) {
throw new NinjaException(ex.getMessage(), ex);
}
return Base64.encode(sha1.digest(key.getEncoded()));
}
}
代码示例来源:origin: wso2/carbon-identity-framework
public static String getPPIDDisplayValue(String value) throws Exception {
if (log.isDebugEnabled()) {
log.debug("Generating display value of PPID : " + value);
}
byte[] rawPpid = Base64.decode(value);
MessageDigest sha1 = MessageDigest.getInstance("SHA1");
sha1.update(rawPpid);
byte[] hashId = sha1.digest();
char[] returnChars = new char[10];
for (int i = 0; i < 10; i++) {
int rawValue = (hashId[i] + 128) % 32;
returnChars[i] = ppidDisplayCharMap[rawValue];
}
StringBuilder sb = new StringBuilder();
sb.append(returnChars, 0, 3);
sb.append("-");
sb.append(returnChars, 3, 4);
sb.append("-");
sb.append(returnChars, 6, 3);
return sb.toString();
}
代码示例来源:origin: wso2/carbon-identity-framework
public static String getHMAC(String secretKey, String baseString) throws SignatureException {
try {
SecretKeySpec key = new SecretKeySpec(secretKey.getBytes(), HMAC_SHA1_ALGORITHM);
Mac mac = Mac.getInstance(HMAC_SHA1_ALGORITHM);
mac.init(key);
byte[] rawHmac = mac.doFinal(baseString.getBytes());
return Base64.encode(rawHmac);
} catch (Exception e) {
throw new SignatureException("Failed to generate HMAC : " + e.getMessage());
}
}
代码示例来源:origin: org.apache.cxf.fediz/fediz-idp-core
private void validateSeparateSignature(Idp idp, String sigAlg, String signature, String relayState,
String samlRequest, String realm) throws Exception {
// Check signature
X509Certificate validatingCert = getValidatingCertificate(idp, realm);
// Process the received SigAlg parameter - fall back to RSA SHA1
String processedSigAlg = null;
if (sigAlg != null && SIG_ALGS.contains(sigAlg)) {
processedSigAlg = sigAlg;
} else {
LOG.debug("Supplied SigAlg parameter is either null or not known, so falling back to use RSA-SHA1");
processedSigAlg = SSOConstants.RSA_SHA1;
}
java.security.Signature sig =
java.security.Signature.getInstance(JCEMapper.translateURItoJCEID(processedSigAlg));
sig.initVerify(validatingCert);
// Recreate request to sign
String requestToSign =
SSOConstants.SAML_REQUEST + "=" + URLEncoder.encode(samlRequest, StandardCharsets.UTF_8.name())
+ "&" + SSOConstants.RELAY_STATE + "=" + URLEncoder.encode(relayState, StandardCharsets.UTF_8.name())
+ "&" + SSOConstants.SIG_ALG + "=" + URLEncoder.encode(processedSigAlg, StandardCharsets.UTF_8.name());
sig.update(requestToSign.getBytes(StandardCharsets.UTF_8));
if (!sig.verify(Base64.decode(signature))) {
LOG.debug("Signature validation failed");
throw new ProcessingException(TYPE.BAD_REQUEST);
}
}
代码示例来源:origin: org.apache.santuario/xmlsec
/**
* Method encodeToElement
*
* @param doc
* @param localName
* @param bytes
* @return an Element with the base64 encoded in the text.
*
*/
public static final Element encodeToElement(Document doc, String localName, byte[] bytes) {
Element el = XMLUtils.createElementInSignatureSpace(doc, localName);
Text text = doc.createTextNode(encode(bytes));
el.appendChild(text);
return el;
}
内容来源于网络,如有侵权,请联系作者删除!