Add secret key test
This commit is contained in:
parent
9118c43da3
commit
be426ee56d
3 changed files with 18 additions and 2 deletions
|
|
@ -102,4 +102,4 @@ then
|
||||||
export BABASHKA_FEATURE_PRIORITY_MAP="${BABASHKA_FEATURE_PRIORITY_MAP:-false}"
|
export BABASHKA_FEATURE_PRIORITY_MAP="${BABASHKA_FEATURE_PRIORITY_MAP:-false}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
"$GRAALVM_HOME/bin/native-image" "${args[@]}"
|
"$GRAALVM_HOME/bin/native-image" "${args[@]}" "$@"
|
||||||
|
|
|
||||||
|
|
@ -197,6 +197,7 @@
|
||||||
java.security.cert.X509Certificate
|
java.security.cert.X509Certificate
|
||||||
javax.crypto.Cipher
|
javax.crypto.Cipher
|
||||||
javax.crypto.Mac
|
javax.crypto.Mac
|
||||||
|
javax.crypto.SecretKey
|
||||||
javax.crypto.SecretKeyFactory
|
javax.crypto.SecretKeyFactory
|
||||||
javax.crypto.spec.GCMParameterSpec
|
javax.crypto.spec.GCMParameterSpec
|
||||||
javax.crypto.spec.PBEKeySpec
|
javax.crypto.spec.PBEKeySpec
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@
|
||||||
expected-sha (String. (.encode (java.util.Base64/getEncoder)
|
expected-sha (String. (.encode (java.util.Base64/getEncoder)
|
||||||
(hmac-sha-256 (.getBytes key-s) data))
|
(hmac-sha-256 (.getBytes key-s) data))
|
||||||
"utf-8")]
|
"utf-8")]
|
||||||
(prn expected-sha)
|
|
||||||
(is (= expected-sha (bb '(do (ns net
|
(is (= expected-sha (bb '(do (ns net
|
||||||
(:import (javax.crypto Mac)
|
(:import (javax.crypto Mac)
|
||||||
(javax.crypto.spec SecretKeySpec)))
|
(javax.crypto.spec SecretKeySpec)))
|
||||||
|
|
@ -34,3 +33,19 @@
|
||||||
(String. (.encode (java.util.Base64/getEncoder)
|
(String. (.encode (java.util.Base64/getEncoder)
|
||||||
(hmac-sha-256 (.getBytes key-s) data))
|
(hmac-sha-256 (.getBytes key-s) data))
|
||||||
"utf-8"))))))))
|
"utf-8"))))))))
|
||||||
|
|
||||||
|
(deftest secretkey-test
|
||||||
|
(is (= 32 (bb '(do (import 'javax.crypto.SecretKeyFactory)
|
||||||
|
(import 'javax.crypto.spec.PBEKeySpec)
|
||||||
|
|
||||||
|
(defn gen-secret-key
|
||||||
|
"Generate secret key based on a given token string.
|
||||||
|
Returns bytes array 256-bit length."
|
||||||
|
[^String secret-token]
|
||||||
|
(let [salt (.getBytes "abcde")
|
||||||
|
factory (SecretKeyFactory/getInstance "PBKDF2WithHmacSHA256")
|
||||||
|
spec (PBEKeySpec. (.toCharArray secret-token) salt 10000 256)
|
||||||
|
secret (.generateSecret factory spec)]
|
||||||
|
(count (.getEncoded secret))))
|
||||||
|
|
||||||
|
(gen-secret-key "foo"))))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue