         (Key) An instance of the Key class corresponding to the ski"
   [msg {:keys [algorithm]}]
   (let [md (MessageDigest/getInstance (name algorithm))]
-    (Hex/toHexString (.digest md (if (string? msg)
-                                   (.getBytes ^String msg)
-                                   msg)))))
+    (->> (if (string? msg)
+           (.getBytes ^String msg)
+           msg)
+         (.digest md)
+         (Hex/toHexString))))
 ;;(hash test-msg {:algorithm :sha384})
 
+(defonce cipher-mode-map {:encrypt Cipher/ENCRYPT_MODE
+                          :decrypt Cipher/DECRYPT_MODE})
+
+(defn %encrypt-or-decrypt
+  ;; https://docs.oracle.com/javase/8/docs/api/javax/crypto/Cipher.html
+  [k text {:keys [algorithm cipher-mode]}]
+  (let [tname (name algorithm)
+        tk (SecretKeySpec. k tname)
+        cipher (doto (Cipher/getInstance tname)
+                 (.init ^java.lang.Integer (cipher-mode-map cipher-mode) tk))]
+    (.doFinal cipher
+              (if (string? text)
+                (.getBytes ^String text)
+                text))))
 
 ;;;encrypt
 (defn encrypt


;; Add provider!
(Security/addProvider (BouncyCastleProvider.))

;;;generate_key
(defn generate-key

        opts (function) hashing function to use
  Returns
        Result(Object):Signature object"
  [priv-key ^bytes digest {:keys [algorithm]}]
  (doto (Signature/getInstance (name algorithm))
    (.initSign priv-key)
    (.update digest)
    (.sign)))

;;; verify
(defn verify
