Suche // Search:

16.03.2010

Formulare mit RC4 verschlüsseln
//
Encrypt Forms with RC4

Basierend auf dem Beispiel Base64 Encryption habe ich ein anderes Beispiel entwickelt, das anstelle von Base64 den Rivest Cipher No.4 Algorythmus (RC4) verwendet.

Der Algorythmus arbeitet innerhalb XFA-Formularen zwar, benötigt aber zuvor etwas Feinschliff.
Damit es beim Verschlüsseln und Entschlüsseln nicht zur Fehler kommt, die dazu führen, dass der Text abgeschnitten wird oder bestimmte Schriftzeichen fehlerhaft verarbeitet werden, muss der eigentliche Algorithmus mit der escape() bzw. unescape() Funktion kombiniert werden.

Für einen möglichst hohen Verschlüsselungsgrad wird aus dem Password des Benutzers ein Hashwert generiert, der mit einem anderen Hashwert kombiniert wird, das sogenannte Salting.
Aus diesem wird dann wiederum ein Hashwert erzeugt, der letzlich zur Ver- und Entschlüsselung verwendet wird.

Based on the example for the Base64 Encryption I developed another example, that uses the Rivest Cipher No. 4 algorithm (RC4).

To work proper in XFA-forms the algorithm needs some final touch.
Otherwise it will produces errors like cuf off text and misinterpreted characters when encrypting oder decrypting the text strings.
Therefore I added the escape() repectively unescape() functions to the algorithm for the enryption and decryption.

For a high ciphering level the form generates a hash-key from the users password which then will be combined with another hash-key (the so-called Salting). From this salted hash-key there will be generated a final hash-key which is used for the en- and decryption.


JavaSript für Verschlüsselung // JavaScript for Encryption:

var CharSetSize = 256;
var RC4_SubstitutionBox = new Array(CharSetSize);


function RC4_crypt (KeyWord, InputTextString)
{
var i, j, k = 0;
var Temp = 0;
var t = 0;
var ModifiedText = "";


for (j = 0; j < CharSetSize; j++)
RC4_SubstitutionBox[j] = j;
j = 0;


for (i=0; i < CharSetSize; i++)
{
j = (j + RC4_SubstitutionBox[i] + KeyWord.charCodeAt(i % KeyWord.length)) % CharSetSize;
Temp = RC4_SubstitutionBox[i];
RC4_SubstitutionBox[i] = RC4_SubstitutionBox[j];
RC4_SubstitutionBox[j] = Temp;
}


for (k=0; k < InputTextString.length; k++)
{
i = (i + 1) % CharSetSize;
j = (j + RC4_SubstitutionBox[i]) % CharSetSize;
Temp = RC4_SubstitutionBox[i];
RC4_SubstitutionBox[i] = RC4_SubstitutionBox[j];
RC4_SubstitutionBox[j] = Temp;
t = (RC4_SubstitutionBox[i] + RC4_SubstitutionBox[j]) % CharSetSize;
ModifiedText = ModifiedText + String.fromCharCode(InputTextString.charCodeAt(k) ^ RC4_SubstitutionBox[t]);
}
return escape(ModifiedText);
}
Klartext // Cleartext:



RC4-verschlüsselter Text // RC4-Encrypted Text:


Beispiel // Example:
https://acrobat.com/#d=35uUne9Hl5V*fZG8ZRWLBA

Keine Kommentare:

Kommentar veröffentlichen