Dieser Artikel beschreibt die von JS implementierte Base64 -Verschlüsselung und Entschlüsselung. Teilen Sie es für Ihre Referenz wie folgt weiter:
Vollständiger Code:
<html> <Head> <titels> Base64 </title> <script Language = javaScript> var base64encodechars = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789+/"; -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1); "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";var base64DecodeChars = new Array( -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1, -1, -1). Var C1, C2, C3; Len = Str.Length; i = 0; out = ""; while (i <len) {c1 = str.charCodeat (i ++) & 0xff; if (i == len) {out += base64Enencodechars.charat (c1 >> 2); out += base64Enencodechars.charat ((c1 & 0x3) << 4); out += "=="; brechen; } c2 = str.charCodeat (i ++); if (i == len) {out += base64Enencodechars.charat (c1 >> 2); out += base64Enencodechars.charat ((C1 & 0x3) << 4) | ((C2 & 0xf0) >> 4)); out += base64Enencodechars.charat ((C2 & 0xf) << 2); out += "="; brechen; } c3 = str.charCodeat (i ++); out += base64Enencodechars.charat (c1 >> 2); out += base64Enencodechars.charat ((C1 & 0x3) << 4) | ((C2 & 0xf0) >> 4)); out += base64Enencodechars.charat (((c2 & 0xf) << 2) | ((C3 & 0xc0) >> 6)); out += base64Enencodechars.charat (C3 & 0x3f); } return out;} function base64Decode (str) {var c1, c2, c3, c4; var i, len, out; Len = Str.Length; i = 0; out = ""; while (i <len) { / * c1 * / do {c1 = base64Decodechars [str.charCodeat (i ++) & 0xff]; } while (i <len && c1 == -1); if (c1 == -1) brechen; / * c2 */ do {c2 = base64Decodechars [str.charCodeat (i ++) & 0xff]; } while (i <len && c2 == -1); if (c2 == -1) brechen; out += string.fromCharCode ((c1 << 2) | ((C2 & 0x30) >> 4)); / * c3 */ do {c3 = str.charCodeat (i ++) & 0xff; if (c3 == 61) kehren aus; C3 = Base64Decodechars [C3]; } while (i <len && c3 == -1); if (c3 == -1) brechen; out += string.fromCharCode (((c2 & 0xf) << 4) | ((C3 & 0x3c) >> 2)); / * c4 */ do {c4 = str.charCodeat (i ++) & 0xff; if (c4 == 61) kehren aus; C4 = Base64Decodechars [C4]; } while (i <len && c4 == -1); if (c4 == -1) brechen; out += string.fromCharCode (((C3 & 0x03) << 6) | C4); } return out;} function utf16to8 (str) {var out, i, len, c; out = ""; Len = Str.Length; für (i = 0; i <len; i ++) {c = str.charCodeat (i); if ((c> = 0x0001) && (c <= 0x007f)) {out += str.charat (i); } else if (c> 0x07ff) {out += string.fromCharCode (0xe0 | ((c >> 12) & 0x0f)); out += string.fromCharCode (0x80 | ((c >> 6) & 0x3f)); out += string.fromCharCode (0x80 | ((c >> 0) & 0x3f)); } else {out += string.fromCharCode (0xc0 | ((c >> 6) & 0x1f)); out += string.fromCharCode (0x80 | ((c >> 0) & 0x3f)); }} return;} function utf8to16 (str) {var out, i, len, c; var char2, char3; out = ""; Len = Str.Length; i = 0; while (i <len) {c = str.charCodeat (i ++); Switch (c >> 4) {Fall 0: Fall 1: Fall 2: Fall 3: Fall 4: Fall 5: Fall 6: Fall 7: // 0xxxxx out += str.charat (i-1); brechen; Fall 12: Fall 13: // 110x xxxx 10xx xxxx char2 = str.charCodeat (i ++); out += string.fromCharCode (((c & 0x1f) << 6) | (char2 & 0x3f)); brechen; Fall 14: // 1110 xxxx 10xx xxxx 10xx xxxx char2 = str.charCodeat (i ++); char3 = str.charCodeat (i ++); out += string.fromCharCode (((c & 0x0f) << 12) | ((char2 & 0x3f) << 6) | ((char3 & 0x3f) << 0)); brechen; }} return;} function doit () {var f = document.f f.output.value = base64EneCode (utf16to8 (f.source.value)) f.decode.value = utf8to16 (Base64Decode (f.output.value)})} </script </hects NAME="f">Original code<BR><TEXTAREA NAME="source" ROWS=4 COLS=60 WRAP="soft"></TEXTAREA><BR><BR>Base64 encode<BR><TEXTAREA NAME="output" ROWS=4 COLS=60 WRAP="soft"></TEXTAREA><BR><BR>Base64 decode<BR><TEXTAREA NAME="decode" ROWS=4 COLS=60 Wrap = "Soft"> </textArea> <br> <br> <Eingabe type = button value = "convert" onclick = "doit ()"> </form> </body>Für die Verschlüsselung und Entschlüsselung von Base64 können Sie sich auch auf die Online -Tools dieser Website beziehen :
Basis64 -Codierungs- und Dekodierungswerkzeug
Weitere verschlüsselte und entschlüsselte Inhalte finden Sie unter:
MD5 Online -Verschlüsselungstool
URL -Hexadezimalverschlüsselungsinstrument
Donner-, Express-, Tornado -URL -Verschlüsselungs-/Entschlüsselungswerkzeuge
Online -SHA1 -Verschlüsselungstool
For more information about JavaScript, please check out the topics of this site: "Summary of JavaScript Encryption and Decryption Skills", "Summary of JavaScript Switching Special Effects and Skills", "Summary of JavaScript Search Algorithm Skills", "Summary of JavaScript Animation Special Effects and Skills", "Summary of JavaScript Errors and Debugging Skills", "Summary of JavaScript Data Structures and Algorithmusfähigkeiten "," Zusammenfassung des JavaScript -Traversal -Algorithmus und der Fähigkeiten "und" Zusammenfassung der Verwendung von JavaScript Mathematical Operation Nutzung ""
Ich hoffe, dieser Artikel wird für JavaScript -Programme aller hilfreich sein.