       (str/replace "_" "/")
       (base64->str)))
 
+(defn safebase64->bytes
+  "Given urlsafe base64 string decode it to bytes."
+  [^String s]
+  (-> (case (mod (count s) 4)
+        2 (str s "==")
+        3 (str s "=")
+        s)
+      (str/replace "-" "+")
+      (str/replace "_" "/")
+      (base64->bytes)))
+
 (defprotocol ByteArray
   "Facility for convert input parameters
 to bytes array with default implementation

  [^String s]
  (String. (base64->bytes s) "UTF8"))

(defn str->sefebase64
  "Given a string, convert it to completely
urlsafe base64 version."
  [^String s]
  (-> (str->base64 s)
      (str/replace #"\s" "")
      (str/replace "=" "")
      (str/replace "+" "-")

  "Convert octets to String."
  ([data]
   (bytes->str data "UTF-8"))
  ([^bytes data, ^String encoding]
   (String. data encoding)))

(defn bytes->hex
  "Convert a byte array to hex
  encoded string."
  [^bytes data]
  (Hex/encodeHexString data))

(defn hex->bytes
