Java Code Examples for org.apache.cxf.common.util.StringUtils#toHexString()
The following examples show how to use
org.apache.cxf.common.util.StringUtils#toHexString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CSRFUtils.java From cxf-fediz with Apache License 2.0 | 6 votes |
public static String getCSRFToken(HttpServletRequest request, boolean create) { if (request != null && request.getSession() != null) { // Return an existing token first String savedToken = (String)request.getSession().getAttribute(CSRF_TOKEN); if (savedToken != null) { return savedToken; } // If no existing token then create a new one, save it, and return it if (create) { String token = StringUtils.toHexString(CryptoUtils.generateSecureRandomBytes(32)); request.getSession().setAttribute(CSRF_TOKEN, token); return token; } } return null; }
Example 2
Source File: MessageDigestUtils.java From cxf with Apache License 2.0 | 5 votes |
public static String generate(byte[] input, String algo) { try { byte[] messageDigest = createDigest(input, algo); return StringUtils.toHexString(messageDigest); } catch (NoSuchAlgorithmException e) { throw new SecurityException(e); } }
Example 3
Source File: OAuthUtils.java From cxf with Apache License 2.0 | 4 votes |
public static String generateRandomTokenKey(int byteSize) { if (byteSize < 16) { throw new OAuthServiceException(); } return StringUtils.toHexString(CryptoUtils.generateSecureRandomBytes(byteSize)); }
Example 4
Source File: DigestAuthSupplier.java From cxf with Apache License 2.0 | 4 votes |
synchronized String generateAuth(String uri, String username, String password) { try { String digAlg = algorithm; if ("MD5-sess".equalsIgnoreCase(digAlg)) { digAlg = "MD5"; } final MessageDigest digester = MessageDigest.getInstance(digAlg); String cnonce = createCnonce(); String a1 = username + ':' + realm + ':' + password; if ("MD5-sess".equalsIgnoreCase(algorithm)) { String tmp2 = StringUtils.toHexString(digester.digest(a1.getBytes(charset))); a1 = tmp2 + ':' + nonce + ':' + cnonce; } String hasha1 = StringUtils.toHexString(digester.digest(a1.getBytes(charset))); String a2 = method + ':' + uri; String hasha2 = StringUtils.toHexString(digester.digest(a2.getBytes(US_ASCII))); final String serverDigestValue; final String ncstring; if (qop == null) { ncstring = null; serverDigestValue = hasha1 + ':' + nonce + ':' + hasha2; } else { ncstring = StringUtils.toHexString(ByteBuffer.allocate(4).putInt(++nc).array()); serverDigestValue = hasha1 + ':' + nonce + ':' + ncstring + ':' + cnonce + ':' + qop + ':' + hasha2; } String response = StringUtils.toHexString(digester.digest(serverDigestValue.getBytes(US_ASCII))); Map<String, String> outParams = new HashMap<>(); if (qop != null) { outParams.put("qop", "auth"); } outParams.put("realm", realm); outParams.put("opaque", opaque); outParams.put("nonce", nonce); outParams.put("uri", uri); outParams.put("username", username); if (ncstring != null) { outParams.put("nc", ncstring); } outParams.put("cnonce", cnonce); outParams.put("response", response); outParams.put("algorithm", algorithm); return new HttpAuthHeader(HttpAuthHeader.AUTH_TYPE_DIGEST, outParams).getFullHeader(); } catch (Exception ex) { throw new RuntimeException(ex); } }
Example 5
Source File: JMSUtil.java From cxf with Apache License 2.0 | 4 votes |
public static String createCorrelationId(final String prefix, long sequenceNum) { return prefix + StringUtils.toHexString(java.nio.ByteBuffer.allocate(Long.BYTES).putLong(sequenceNum).array()); }