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 :)