Skip to content

Instantly share code, notes, and snippets.

@maxfindel
Last active April 25, 2017 11:11
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 maxfindel/83794af63d030f08295444187b5a6f33 to your computer and use it in GitHub Desktop.
Save maxfindel/83794af63d030f08295444187b5a6f33 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.
module = do ->
enc: (key_str, pt1_str) ->
key = new Buffer key_str
pt1 = new Buffer pt1_str
{encrypt} = require 'triplesec'
encrypt { key, data : pt1 }, (err, ciphertext) ->
console.log ciphertext.toString('base64')
dec: (key_str, ciphertext_str) ->
key = new Buffer key_str
ciphertext = new Buffer ciphertext_str, 'base64'
{decrypt} = require 'triplesec'
decrypt { key, data : ciphertext }, (err, pt2) ->
if !!pt2
console.log pt2.toString('utf8')
else
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