JScriptEncrypt - Practical Guide

This page contains questions and answers regarding the library. It's purpose is to give You answers to practical problems and to allow You to follow and understand the library revisions.

1. E-mailing the encrypted text

Date posted: Aug 4, 2000

Bill wrote:

I was working with your JavaScript Encryption example and wanted to use it to encrypt text, copy it into email, and then have the person receiving the email be able to copy and paste it back into your JavaScript example to be able to read the text.

However, when I do this using the same password, the encrypted text will not decrypt into anything readable. Is there some random number generator that comes into play or a bug in the Java Virtual Machine?

Thanks for your assistance......Bill

The answer:

Dear Bill!

I'll assume you have used "new lines used" check mark, as it was explained in the User's Guide. However, your experiment didn't work! Why was that?

The reason is simple to understand.

All of the encrypted text is one single line with spaces in it. When you paste the encrypted text into your e-mail editor it reformats the text - it breaks up this single very long line into several lines, so they fit nicely into the viewing pane.

This splitting is done by inserting "new line" characters (0Ah 0Dh pairs) into the original single line of text. What this means is that the encrypted text gets modified!

Naturaly, decryption does not produce the original plain text no more.

The solution is not too dificult.

You should use escape() function on the encrypted text, copy it and paste into the email editor. The escaped text won't contain any blanks no more.

After the e-mail is received, unescape() function should be used on the encrypted text before it's passed to the decryption algorithm.

But note, if during the transport of e-mail message any blanks (spaces, tabs or new-lines) get inserted, the first thing to do is to remove them.

To save you from doing this on hand, I have created another page that does all that's required. Simply enter the text, encrypt it, and copy into the e-mail editor. See the e-mail encryption page.

When the e-mail is received, copy the message into the page and decrypt.

Just as you intended in the first place!

Related documents

This document: http://www.inet.hr/~tsereg/jse/practice.html