nl_tokens: Encrypts data with a public key
pl_tokens: function encrypt ( publicKeyDataOrFile , data ) { const deferred = q . defer ( ) ; let publicKeyPromise ; const getPublicKey = function getPublicKey ( publicKeyFile ) { const publicKeyDeferred = q . defer ( ) ; fs . readFile ( publicKeyFile , ( err , publicKey ) => { if ( err ) { logger . warn ( 'Error reading public key:' , err ) ; publicKeyDeferred . reject ( err ) ; } else { publicKeyDeferred . resolve ( publicKey ) ; } } ) ; return publicKeyDeferred . promise ; } ; if ( typeof data !== 'string' ) { deferred . reject ( new Error ( 'data must be a string' ) ) ; return deferred . promise ; } if ( publicKeyDataOrFile . startsWith ( '-----BEGIN PUBLIC KEY-----' ) ) { publicKeyPromise = q ( publicKeyDataOrFile ) ; } else { publicKeyPromise = getPublicKey ( publicKeyDataOrFile ) ; } publicKeyPromise . then ( ( publicKey ) => { let encrypted ; try { encrypted = crypto . publicEncrypt ( publicKey , util . createBufferFrom ( data ) ) ; deferred . resolve ( encrypted . toString ( 'base64' ) ) ; } catch ( err ) { logger . warn ( 'Error encrypting data:' , err ) ; deferred . reject ( err ) ; } } ) . catch ( ( <mask> ) => { logger . warn ( 'Unable to get public key:' , err ) ; deferred . reject ( err ) ; } ) ; return deferred . promise ; }