<reponame>Ragemon/NEIP_django_api<filename>frontend/node_modules/crypto-browserify/test/public-encrypt.js<gh_stars>0var test = require('tape')
var crypto1 = require('../')
var rsa = {
  'private': '9q3vfhm7l33rus21toc8fndupq76itje',
  'public': '9q3vfhm7l33rus21toc8fndupq76itje'
}
var crypto2 = require('public-encrypt/browser')
rsa.private = new Buffer(rsa.private, 'hex')
rsa.public = new Buffer(rsa.public, 'hex')
var encrypted = '0bcd6462ad7a563be2d42b0b73e0b0a163886304e7723b025f97605144fe1781e84acdc4031327d6bccd67fe13183e8fbdc8c5fe947b49d011ce3ebb08b11e83b87a77328ca57ee77cfdc78743b0749366643d7a21b2abcd4aa32dee9832938445540ee3007b7a70191c8dc9ff2ad76fe8dfaa5362d9d2c4b31a67b816d7b7970a293cb95bf3437a301bedb9f431b7075aa2f9df77b4385bea2a37982beda467260b384a58258b5eb4e36a0e0bf7dff83589636f5f97bf542084f0f76868c9f3f989a27fee5b8cd2bfee0bae1eae958df7c3184e5a40fda101196214f371606feca4330b221f30577804bbd4f61578a84e85dcd298849f509e630d275280'

test('publicEncrypt/privateDecrypt', function (t) {
  t.test('can decrypt', function (t) {
    t.plan(2)
    // note encryption is ranomized so can't test to see if they encrypt the same
    t.equals(crypto1.privateDecrypt(rsa.private, new Buffer(encrypted, 'hex')).toString(), 'hello there I am a nice message', 'decrypt it properly')
    t.equals(crypto2.privateDecrypt(rsa.private, new Buffer(encrypted, 'hex')).toString(), 'hello there I am a nice message', 'decrypt it properly')
  })
  t.test('can round trip', function (t) {
    t.plan(2)
    var msg = 'this is a message'
    // note encryption is ranomized so can't test to see if they encrypt the same
    t.equals(crypto1.privateDecrypt(rsa.private, crypto2.publicEncrypt(rsa.public, new Buffer(msg))).toString(), msg, 'round trip it')
    t.equals(crypto2.privateDecrypt(rsa.private, crypto1.publicEncrypt(rsa.public, new Buffer(msg))).toString(), msg, 'round trip it')
  })
})

test('privateEncrypt/publicDecrypt', function (t) {
  t.test('can round trip', function (t) {
    t.plan(2)
    var msg = 'this is a message'
    // note encryption is ranomized so can't test to see if they encrypt the same
    t.equals(crypto1.publicDecrypt(rsa.public, crypto2.privateEncrypt(rsa.private, new Buffer(msg))).toString(), msg, 'round trip it')
    t.equals(crypto2.publicDecrypt(rsa.public, crypto1.privateEncrypt(rsa.private, new Buffer(msg))).toString(), msg, 'round trip it')
  })
})
