Add javax.crypto classes necessary for calculating hmac shas. (#1066)
* Add javax.crypto classes necessary for calculating hmac shas. * Add hmac-256-sha test for javax.crypto.
This commit is contained in:
parent
bd79e6344a
commit
5940b95cd2
2 changed files with 33 additions and 0 deletions
|
|
@ -204,6 +204,8 @@
|
|||
java.net.http.WebSocket$Builder
|
||||
java.net.http.WebSocket$Listener
|
||||
java.security.cert.X509Certificate
|
||||
javax.crypto.Mac
|
||||
javax.crypto.spec.SecretKeySpec
|
||||
javax.net.ssl.SSLContext
|
||||
javax.net.ssl.SSLParameters
|
||||
javax.net.ssl.TrustManager
|
||||
|
|
|
|||
31
test/babashka/crypto_test.clj
Normal file
31
test/babashka/crypto_test.clj
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
(ns babashka.crypto-test
|
||||
(:require [babashka.test-utils :as test-utils]
|
||||
[clojure.edn :as edn]
|
||||
[clojure.test :refer [deftest is]])
|
||||
(:import (javax.crypto Mac)
|
||||
(javax.crypto.spec SecretKeySpec)))
|
||||
|
||||
(defn bb [& exprs]
|
||||
(edn/read-string (apply test-utils/bb nil (map str exprs))))
|
||||
|
||||
(defn hmac-sha-256 [key data]
|
||||
(let [algo "HmacSHA256"
|
||||
mac (Mac/getInstance algo)]
|
||||
(.init mac (SecretKeySpec. key algo))
|
||||
(.doFinal mac (.getBytes data "UTF-8"))))
|
||||
|
||||
(deftest hmac-sha-256-test
|
||||
(let [key-s "some-key"
|
||||
data "some-data"
|
||||
expected-sha (String. (hmac-sha-256 (.getBytes key-s) data))]
|
||||
(is (= expected-sha (bb '(do (ns net
|
||||
(:import (javax.crypto Mac)
|
||||
(javax.crypto.spec SecretKeySpec)))
|
||||
(defn hmac-sha-256 [key data]
|
||||
(let [algo "HmacSHA256"
|
||||
mac (Mac/getInstance algo)]
|
||||
(.init mac (SecretKeySpec. key algo))
|
||||
(.doFinal mac (.getBytes data "UTF-8"))))
|
||||
(let [key-s "some-key"
|
||||
data "some-data"]
|
||||
(String. (hmac-sha-256 (.getBytes key-s) data)))))))))
|
||||
Loading…
Reference in a new issue