Created
September 5, 2017 18:12
-
-
Save dtinth/d805ff93abc49b27ea07de95bdce9889 to your computer and use it in GitHub Desktop.
Node.js encrypt -> Clojure decrypt RSA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn load-private-key | |
[key-str] | |
(crypto/decode-private-key {:algorithm "RSA" | |
:bytes (-> key-str | |
crypto/decode-base64)})) | |
(defn decrypt-str | |
[private-key text-to-decrypt] | |
(let [cipher (crypto/create-cipher "RSA/ECB/OAEPWithSHA1AndMGF1Padding")] | |
(crypto/decrypt private-key | |
(crypto/decode-base64 text-to-decrypt) | |
cipher))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var RSA = require('node-rsa') | |
var publicKey = '[...]' | |
var key = new RSA(new Buffer(publicKey, 'base64'), 'pkcs8-public-der') | |
key.encrypt(text).toString('base64') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn make-key-pair | |
[] | |
(let [key-pair (crypto/generate-key-pair)] | |
{:public (-> key-pair | |
crypto/public-key | |
crypto/encoded | |
crypto/encode-base64-as-str) | |
:private (-> key-pair | |
crypto/private-key | |
crypto/encoded | |
crypto/encode-base64-as-str)})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment