Clojure base64 encoding

后端 未结 6 1885
深忆病人
深忆病人 2020-12-09 17:31

I want something as simple as \"string\" -> base64. With the older base64.encode-str it was easy (and sounded \"more clojure\", but the newer clojure.data.codec.base64

6条回答
  •  再見小時候
    2020-12-09 18:07

    There's one more step needed for the other answer: converting the byte-array result of encode into a string. Here's what I do:

    (:require [clojure.data.codec.base64 :as b64])
    
    (defn string-to-base64-string [original]
      (String. (b64/encode (.getBytes original)) "UTF-8"))
    

提交回复
热议问题