RSA decrypt long messages (javascript) I am attempting to encrypty/decrypt a long message in RSA using javascript (with crypto-js and jsbn libraries).

I posted this on stackoverflow too but I figured someone here on crypto might be able to help as well.

so far, to encrypt/decrypt short messages I have the following code:

function encrypt(signedCert, msg) { 
    key = new RSAKey();
    m = asciiToHex(msg); 
    m = new BigInteger(m, 16)
    //n and e retrieved from the digital certificate 
    key.setPublic(signedCert.msg.subject.pk.n, signedCert.msg.subject.pk.e);
    var ctxt = key.doPublic(m).toString(16);
    return ctxt;
}

function decrypt(sk, ctxt) {
    key = new RSAKey();
    c = new BigInteger(ctxt, 16);
    key.setPrivate(sk.n, sk.e, sk.d);
    var ptxt = key.doPrivate(c).toString(16);
    var ptxt = hexToAscii(ptxt);
    return ptxt;
}


this works like a charm when the message is short. but, for the life of me, I can't figure out how to encrypt/decrypt when the message is long!

can anyone help? thanks :)
I don't know much about the library you're using but it looks like you're trying to encrypt/decrypt the cipher-text using RSA directly.

Using RSA in this way isn't secure unless extreme care is taken.

This isn't the correct way to use RSA. Typically, what you do is use RSA to encrypt a secret key. This secret key is then used with a conventional symmetric cipher, such as AES, to encrypt your payload. Then your payload can be any length you like.

There are standards such as PCKS#1 v2.0 that deal with how to do this securely.