Chand Mohammad
Chand Mohammad

Reputation: 1

Encrypt user password with jquery and decrypt it with Clojure

I want to encrypt password at client side and decrypt password at server side. I am using below code in js to encrypt password for json request

CryptoJS.AES.encrypt("password", "").toString();

Which outputs

"U2FsdGVkX1996HeoxCde3m8JCGvIbt1PwnByR9EOb4w="

And i am using below code for decrypt password at server

(defn decrypt [text key]
  (let [cipher (get-cipher Cipher/DECRYPT_MODE key)]
    (String. (.doFinal cipher (debase64 text))))) 

(decrypt "password" "")

Which outputs

BadPaddingException Given final block not properly padded com.sun.crypto.provider.CipherCore.doFinal (CipherCore.java:811)

I am not getting way how to encrypt at js and decrypt at serevr please help me thanks

Upvotes: 0

Views: 1026

Answers (1)

gfredericks
gfredericks

Reputation: 1332

Should you be passing the encrypted password ("U2FsdGVkX1996HeoxCde3m8JCGvIbt1PwnByR9EOb4w=") to the decrypt function instead of the string "password"?

Upvotes: 1

Related Questions