//       telegram.link
//
//       Copyright 2014 Enrico Stara 'enrico.stara@gmail.com'
//       Released under the MIT license
//       http://telegram.link

// Export the classes
exports.PublicKey = require('./public_key');
exports.PQFinder = require('./pq_finder');

// Export functions
exports.createSHA1Hash = createSHA1Hash;
exports.createRandomBuffer = createRandomBuffer;
exports.createNonce = createNonce;

// Import dependencies
var crypto = require('crypto');
var BigInteger = require('jsbn');


// Create SHA1 hash
function createSHA1Hash(buffer) {
    var sha1sum = crypto.createHash('sha1');
    sha1sum.update(buffer);
    return new Buffer(sha1sum.digest());
}

// Create a random Buffer
function createRandomBuffer(bytesLength) {
    return new Buffer(crypto.randomBytes(bytesLength));
}

// Create a new nonce
function createNonce(bytesLength) {
    return '0x' + createRandomBuffer(bytesLength).toString('hex');
}

// RSA encrypt function, param: { key: publicKey, message: messageToBeEncrypted }
function  rsaEncrypt (param) {


}

//            var seed = this._createRandomBuffer(255 - hash.length - pqInnerData.length);

@@ -407,16 +407,49 @@
 teNonce;
+%0Aexports.rsaEncrypt = rsaEncrypt;
 %0A%0A// Imp
@@ -532,17 +532,16 @@
 sbn');%0A%0A
-%0A
 // Creat
@@ -670,27 +670,16 @@
  return 
-new Buffer(
 sha1sum.
@@ -686,17 +686,16 @@
 digest()
-)
 ;%0A%7D%0A%0A// 
@@ -1017,147 +1017,1403 @@
 sage
-ToBeEncrypted %7D%0Afunction  rsaEncrypt (param) %7B%0A%0A%0A%7D%0A%0A//            var seed = this._createRandomBuffer(255 - hash.length - pqInnerData.length);
+Buffer %7D%0Afunction rsaEncrypt(param) %7B%0A    var logger = require('../util/logger')('crypto.rsaEncrypt');%0A%0A    var publicKey = param.key;%0A    var messageBuffer = param.message;%0A    var messageLength = messageBuffer.length;%0A    if (!messageBuffer %7C%7C messageLength %3E 255) %7B%0A        logger.warn('Message is undefined or exceeds 255 bytes length.');%0A        return;%0A    %7D%0A    if (messageLength %3C 255) %7B%0A        // Add random bytes as padding%0A        var paddingLength = 255 - messageLength;%0A        messageBuffer = Buffer.concat(%5BmessageBuffer, createRandomBuffer(paddingLength)%5D);%0A    %7D%0A    if (logger.isDebugEnabled()) logger.debug('Buffer to be encrypt contains: message(%25s) and total length %25s',%0A        messageLength, messageBuffer.length);%0A    // Encrypt the message%0A    var modulus = new BigInteger(publicKey.getModulus(), 16);%0A    var exponent = new BigInteger(publicKey.getExponent(), 16);%0A    var message = new BigInteger(messageBuffer);%0A    if (logger.isDebugEnabled()) logger.debug('Message = %25s', message);%0A    var encryptedMessage = new Buffer(message.modPowInt(exponent, modulus).toByteArray());%0A    if(encryptedMessage.length %3E 256) %7B%0A        encryptedMessage = encryptedMessage.slice(encryptedMessage.length - 256);%0A    %7D%0A    if (logger.isDebugEnabled()) logger.debug('Encrypted message(%25s) = %25s', encryptedMessage.length, encryptedMessage.toString('hex'));%0A    return encryptedMessage;%0A%7D
 %0A

Add RSA encryption function to ‘crypto’ module