Created
April 25, 2017 15:17
-
-
Save maxfindel/1540eeea63c33cdea11dc5b5f7fa9967 to your computer and use it in GitHub Desktop.
Importable implementation of Keybase's Triplesec (symetric encryption) to be run comfortably from ruby and other languages. Raw
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 module; | |
module = (function() { | |
return { | |
enc: function(key_str, pt1_str) { | |
var encrypt, key, pt1; | |
key = new Buffer(key_str); | |
pt1 = new Buffer(pt1_str); | |
encrypt = require('triplesec').encrypt; | |
return encrypt({ | |
key: key, | |
data: pt1 | |
}, function(err, ciphertext) { | |
return console.log(ciphertext.toString('base64')); | |
}); | |
}, | |
dec: function(key_str, ciphertext_str) { | |
var ciphertext, decrypt, key; | |
key = new Buffer(key_str); | |
ciphertext = new Buffer(ciphertext_str, 'base64'); | |
decrypt = require('triplesec').decrypt; | |
return decrypt({ | |
key: key, | |
data: ciphertext | |
}, function(err, pt2) { | |
if (!!pt2) { | |
return console.log(pt2.toString('utf8')); | |
} else { | |
return console.log("error"); | |
} | |
}); | |
} | |
}; | |
})(); | |
exports.enc = module.enc; | |
exports.dec = module.dec; | |
// Example usage in ruby: | |
// key = '1234' | |
// msg = 'secret message' | |
// enc = (`coffee -e "t=require('./node/triplesec.coffee');t.enc('#{key}','#{msg}')"`).gsub(/\n/,'') | |
// dec = (`coffee -e "t=require('./node/triplesec.coffee');t.dec('#{key}','#{enc}')"`).gsub(/\n/,'') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment