Last active
April 25, 2017 11:11
-
-
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.
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
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