Skip to content

Instantly share code, notes, and snippets.

@dtinth
Created September 5, 2017 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dtinth/d805ff93abc49b27ea07de95bdce9889 to your computer and use it in GitHub Desktop.
Save dtinth/d805ff93abc49b27ea07de95bdce9889 to your computer and use it in GitHub Desktop.
Node.js encrypt -> Clojure decrypt RSA
(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)))
var RSA = require('node-rsa')
var publicKey = '[...]'
var key = new RSA(new Buffer(publicKey, 'base64'), 'pkcs8-public-der')
key.encrypt(text).toString('base64')
(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