aboutsummaryrefslogtreecommitdiff
path: root/nodejs
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2015-11-01 09:56:07 +0300
committerIgor Pashev <pashev.igor@gmail.com>2015-11-01 09:56:07 +0300
commitaf7c57b627c6b83e3d342d9e6c4f95b6041612d8 (patch)
treef3244b1b213a1bba586e0991a5194ff4673c22b3 /nodejs
downloadzerobin-af7c57b627c6b83e3d342d9e6c4f95b6041612d8.tar.gz
Initial commit1.0.0
Diffstat (limited to 'nodejs')
-rw-r--r--nodejs/Main.hs32
-rw-r--r--nodejs/decrypt.js11
2 files changed, 43 insertions, 0 deletions
diff --git a/nodejs/Main.hs b/nodejs/Main.hs
new file mode 100644
index 0000000..e1acb5d
--- /dev/null
+++ b/nodejs/Main.hs
@@ -0,0 +1,32 @@
+{-# LANGUAGE OverloadedStrings #-}
+
+module Main where
+
+import System.Environment (getArgs)
+import System.Process (callProcess)
+import ZeroBin.SJCL (encrypt)
+import ZeroBin.Utils (makePassword)
+import qualified Data.Aeson as JSON
+import qualified Data.ByteString as BS
+import qualified Data.ByteString.Char8 as C
+import qualified Data.ByteString.Lazy as L
+
+-- nodejs is a Debian's thing, others may have simple "node"
+
+getText :: IO BS.ByteString
+getText = do
+ args <- map C.pack `fmap` getArgs
+ if null args
+ then return "heinrich hertz"
+ else return . BS.intercalate " " $ args
+
+main :: IO ()
+main = do
+ password <- makePassword 32
+ text <- getText
+ cont <- encrypt password text
+ callProcess "nodejs" [ "nodejs/decrypt.js"
+ , password
+ , C.unpack . L.toStrict $ JSON.encode cont
+ ]
+
diff --git a/nodejs/decrypt.js b/nodejs/decrypt.js
new file mode 100644
index 0000000..1fa3a62
--- /dev/null
+++ b/nodejs/decrypt.js
@@ -0,0 +1,11 @@
+/* npm install sjcl */
+
+var sjcl = require('sjcl')
+
+var args = process.argv.slice(2)
+ , pass = args[0]
+ , cont = args[1]
+
+var out = sjcl.decrypt(pass, cont)
+console.log(out)
+