How to use ASP for Base64 encryption

xiaoxiao2021-03-06  58

<% '----------------------------------------------- - 'function function: text encryption decryption Base64 algorithm' encryption function: base64encode (str) AS String 'Decryption function: base64decode (str) AS String' ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------

Const Base_64_map_init = "Abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789 /" DIM NL 'ZERO BASED ARRAYS DIM BASE64ECMAP (63) DIM Base64Decmap (127)

'Must Be Called Before Using Anything Else Public Sub INITCODECS ()' Init Vars NL = "

" & chr (13) & chr (10) 'Setup Base 64 DIM MAX, IDX MAX = LEN (Base_64_map_init) for id = 0 to max - 1 'one based string base64encmap (idx) = mid (base_64_map_init, idx 1, 1) Next for idx = 0 to max - 1 base64decmap (ASC (Base64encmap (IDX)) = idx next End Sub

'Encode Base 64 Encoded String Public Function Base64Encode (Plain) IF LEN (Plain) = 0 dam * 3 ndx = 1 do while ndx <= by3 first = ASC (MID (Plain, NDX 0, 1)) Second = ASC (MID (Plain, NDX 1, 1)) Third = ASC (MID (plain, NDX 2, 1)) RET = RET & BASE64ENCMAP ((first / 4) and 63) RET = RET & BASE64ENCMAP ((First * 16) and 48) (Second / 16) and 15) RET = RET & Base64encmap ((Second * 4) and 60) ((Third / 64) and 3)) RET = RET & BASE64ENCMAP (Third and 63) NDX = NDX 3 Loop 'Check for Stragglers if by3

'Decode base 64 encoded string PUBLIC FUNCTION base64Decode (scrambled) if len (scrambled) = 0 then base64Decode = "" exit function end if' ignore padding dim realLen realLen = len (scrambled) do while mid (scrambled, realLen, 1) = "=" = "= Reallen - 1 Loop Dim Ret, NDX, BY4, FIRST, SECOND, THIRD, FOURTH RET =" "BY4 = (Reallen / 4) * 4 ndx = 1 do while ndx <= by4 first = base64decmap (ASC (MID (Scrambed, NDX 0, 1)))))) "Scrambled, NDX 1, 1)))))" 3))) "Scrambled, NDX 2, 1))) Fourt (MID (Scrambed, NDX 2, 1)) = Base64Decmap (ASC (Scrambled, NDX 3, 1))) RET = RET & CHR ((First * 4) and 255) (Second / 16) and 3)) RET = RET & CHR ((( (Second * 16) and 255) (THIRD / 4) and 15)) RET = RET & CHR ((THIRD * 64) and 255) (Fourth and 63)) NDX = NDX 4 loop 'Check for Stragglers, Will BE 2 or 3 Characters if ndx

转载请注明原文地址:https://www.9cbs.com/read-113226.html

New Post(0)