<script language= "javascript" runat= "Server" >varKeystr = "Abcdefghijklmnop" + "qrstuvwxyzabcdef" + "GHIJKLMNOPQRSTUV" + "wxyz012 3456789+/"+" = "; functionencode64 (Input) {input=Escape (input); varOutput = ""; varCHR1, CHR2, CHR3 = ""; varENC1, Enc2, enc3, Enc4 = ""; vari = 0; Do{chr1= Input.charcodeat (i++); CHR2= Input.charcodeat (i++); CHR3= Input.charcodeat (i++); Enc1= Chr1 >> 2; ENC2= ((Chr1 & 3) << 4) | (CHR2 >> 4); Enc3= ((CHR2 &) << 2) | (CHR3 >> 6); Enc4= CHR3 & 63; if(IsNaN (CHR2)) {enc3= ENC4 = 64; } Else if(IsNaN (CHR3)) {Enc4= 64; } Output= output +Keystr.charat (ENC1)+Keystr.charat (ENC2)+Keystr.charat (enc3)+Keystr.charat (ENC4); CHR1= CHR2 = CHR3 = ""; Enc1= ENC2 = Enc3 = Enc4 = ""; } while(I <input.length); returnoutput; } functiondecode64 (input) {varOutput = ""; varCHR1, CHR2, CHR3 = ""; varENC1, Enc2, enc3, Enc4 = ""; vari = 0; //Remove all characters that is not a -Z, A-Z, 0-9, +,/, or = varBase64test =/[^a-za-z0-9\+\/\=]/G; if(base64test.exec (input)) {alert ("There were invalid base64 characters in the input text.\n" + "Valid base64 characters is a-Z, A-Z, 0-9, ' + ' , '/', and ' = ' \ n ' + ' Expect errors in decoding. '); } Input= Input.replace (/[^a-za-z0-9\+\/\=]/g, ""); Do{enc1= Keystr.indexof (Input.charat (i++)); ENC2= Keystr.indexof (Input.charat (i++)); Enc3= Keystr.indexof (Input.charat (i++)); Enc4= Keystr.indexof (Input.charat (i++)); CHR1= (enc1 << 2) | (Enc2 >> 4); CHR2= ((Enc2 &) << 4) | (Enc3 >> 2); CHR3= ((enc3 & 3) << 6) |Enc4; Output= output +String.fromCharCode (CHR1); if(Enc3! = 64) {Output= output +String.fromCharCode (CHR2); } if(Enc4! = 64) {Output= output +String.fromCharCode (CHR3); } chr1= CHR2 = CHR3 = ""; Enc1= ENC2 = Enc3 = Enc4 = ""; } while(I <input.length); returnunescape (output); } </script>
Javascript Base64 Encrypted decryption code