📄 identityutil.java
字号:
package org.wso2.solutions.identity.util;import org.apache.axiom.om.impl.dom.factory.OMDOMFactory;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.apache.xml.security.utils.Base64;import org.w3c.dom.Document;import org.w3c.dom.Node;import java.security.MessageDigest;public class IdentityUtil { private static Log log = LogFactory.getLog(IdentityUtil.class); private final static char[] ppidDisplayCharMap = new char[] { 'Q', 'L', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'M', 'N', 'P', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' }; private static Document importerDoc = null; 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]; } StringBuffer sb = new StringBuffer(); sb.append(returnChars, 0, 3); sb.append("-"); sb.append(returnChars, 3, 4); sb.append("-"); sb.append(returnChars, 6, 3); return sb.toString(); } /** * Serialize the given node to a String. * @param node Node to be serialized. * @return The serialized node as a java.lang.String instance. */ public static String nodeToString(Node node) { if(importerDoc == null) { OMDOMFactory fac = new OMDOMFactory(); importerDoc = (Document)fac.createOMDocument(); } //Import the node as an AXIOM-DOOM node and use toSting() Node axiomNode = importerDoc.importNode(node, true); return axiomNode.toString(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -