private String encode(Map.Entry<String, String> entry) { return S.concat(entry.getKey(), "=", Codec.encodeUrl(entry.getValue())); }
/** * Decode Base64 encoded string * * @param str the string to be decoded * @return decoded string */ public static String decodeBASE64(String str) { return new String(Codec.decodeBase64(str), Charsets.UTF_8); }
protected static String encodePart(String part) { return Codec.encodeUrlSafeBase64(part); } protected static String encodePart(byte[] part) {
@Override public String path() { // cannot use path as it cut the URI like // "/gh/325/data/foo=3;bar=6/key/bar" // to "/gh/325/data/foo=3" // and put "bar=6/key/bar" as path parameters //return hse.getRequestPath(); if (null == path) { path = hse.getPathParameters().isEmpty() ? hse.getRelativePath() : Codec.decodeUrl(hse.getRequestURI()); } return path; }
/** * Build an hexadecimal MD5 hash for a String * * @param value The String to hash * @return An hexadecimal Hash */ public static String hexMD5(String value) { try { MessageDigest messageDigest = MessageDigest.getInstance("MD5"); messageDigest.reset(); messageDigest.update(value.getBytes("utf-8")); byte[] digest = messageDigest.digest(); return byteToHexString(digest); } catch (Exception ex) { throw new UnexpectedException(ex); } }
/** * Encode a string using Base64 encoding * * @param str the string to be encoded * @return encoded string */ public static String encodeBASE64(String str) { return Codec.encodeBase64(str); }
public boolean verifyHash(String content, String hash) { int len = hash.length(); int padding = 4 - len % 4; if (padding > 0) { hash = S.concat(hash, S.times(Codec.URL_SAFE_BASE64_PADDING_CHAR, padding)); } byte[] yourHash = Codec.decodeUrlSafeBase64(hash); return verifyHash(content.getBytes(UTF_8), yourHash); }
byte[] ba0 = Codec.hexStringToByte(value); byte[] baVal = new byte[ba0.length - 16]; System.arraycopy(ba0, 0, baVal, 0, ba0.length - 16);
/** * Alias of {@link #UUID()} * @return an UUID string */ public static String uuid() { return UUID(); }
@Override public String path() { // cannot use path as it cut the URI like // "/gh/325/data/foo=3;bar=6/key/bar" // to "/gh/325/data/foo=3" // and put "bar=6/key/bar" as path parameters //return hse.getRequestPath(); if (null == path) { path = hse.getPathParameters().isEmpty() ? hse.getRelativePath() : Codec.decodeUrl(hse.getRequestURI()); } return path; }
/** * Build an hexadecimal SHA1 hash for a String * * @param value The String to hash * @return An hexadecimal Hash */ public static String hexSHA1(String value) { try { MessageDigest md; md = MessageDigest.getInstance("SHA-1"); md.update(value.getBytes("utf-8")); byte[] digest = md.digest(); return byteToHexString(digest); } catch (Exception ex) { throw new UnexpectedException(ex); } }
/** * Encode a string using Base64 encoding * * @param str the string to be encoded * @return encoded string */ public static String encodeBASE64(String str) { return Codec.encodeBase64(str); }
public boolean verifyHash(String content, String hash) { int len = hash.length(); int padding = 4 - len % 4; if (padding > 0) { hash = S.concat(hash, S.times(Codec.URL_SAFE_BASE64_PADDING_CHAR, padding)); } byte[] yourHash = Codec.decodeUrlSafeBase64(hash); return verifyHash(content.getBytes(UTF_8), yourHash); }
byte[] ba0 = Codec.hexStringToByte(value); byte[] baVal = new byte[ba0.length - 16]; System.arraycopy(ba0, 0, baVal, 0, ba0.length - 16);
/** * Alias of {@link #UUID()} * @return an UUID string */ public static String uuid() { return UUID(); }
private static String randomKey() { return Codec.encodeUrl(S.random()); } }
protected static String encodePart(byte[] part) { return Codec.encodeUrlSafeBase64(part); }
/** * Decode Base64 encoded string * * @param str the string to be decoded * @return decoded string */ public static String decodeBASE64(String str) { return new String(Codec.decodeBase64(str), Charsets.UTF_8); }
@Override protected String deserialize(String ticket, Map<String, String> payload) { if (ticket.startsWith(MARKER)) { ticket = ticket.substring(MARKER_LEN); } Token token = crypto.parseToken(ticket); if (token.notValid()) { return null; } List<String> payloadList = token.payload(); for (String item : payloadList) { $.T2<String, String> t2 = decode(item); payload.put(t2._1, Codec.decodeUrl(t2._2)); } return token.id(); }
/** * Build an hexadecimal MD5 hash for a String * * @param value The String to hash * @return An hexadecimal Hash */ public static String hexMD5(String value) { try { MessageDigest messageDigest = MessageDigest.getInstance("MD5"); messageDigest.reset(); messageDigest.update(value.getBytes("utf-8")); byte[] digest = messageDigest.digest(); return byteToHexString(digest); } catch (Exception ex) { throw new UnexpectedException(ex); } }