返回列表 发帖

[原创文章] ASP编写的加密和解密类

class Base64Class
. }* G1 J6 v5 [# r  rem Const 8 a7 o" P, o) G6 q, ^
  dim sBASE_64_CHARACTERS'转化码
( O& o5 K9 U# b' S4 p  dim lenString '计算字符串的长度 2 z. H, z# s1 R
  dim iCount '计数器   L, N- P6 T5 T- ~
  dim returnValue '返回值
( j) }. q4 h% [7 u4 |  dim tempChar'缓存字符
( B: [7 I) e9 T& {  dim tempString'缓存字符串 ; A  n1 M8 E( R& t* o: ^" d
  dim paramString '参数字符串
1 h  [1 f2 O; H" z, P/ |) c  dim temHex'缓存缓存十六进制 6 n% w/ y& D& ~. k
  dim tempLow'缓存低位
( P. }* ?. i0 R( q2 X( E7 s- M  dim tempHigh'缓存高位 5 f4 r# N8 o: K" l+ g# B1 x
  dim mod3String'
2 h* o" E3 b0 l$ u3 D  dim mod4String'
+ x* `1 g9 y' a+ [: ~2 c6 C& q  dim tempBinary'
: e% V/ R- m% A! Y$ F  dim tempByteOne'
9 w0 e5 ^; p0 j, D, ~  dim tempByteTwo' ' P6 [) ~. M3 r( I* g
  dim tempByteThree'
, L' C; J* T3 g. {9 b  dim tempByteFour'
. P& ^' e" b5 ~% S* g( E1 e0 F3 {8 l  dim tempSaveBitsOne' ( A  ]7 ^; l# l$ w- N- _1 w1 B+ G  A
  dim tempSaveBitsTwo'
+ k8 x) ]" i* x9 Q' d8 Y  '********************************************: l: D, _' T+ F9 ^% h* r! q
  'begin初始化类
& |3 `% S) A1 [' H  '******************************************** . e) f' O2 c& y* l) n- R
  private sub Class_Initialize()
$ @9 @" V  h$ ^5 i  sBASE_64_CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" end sub
' [  e& t. n  [7 ?+ H  '********************************************
  W) F- r" G" A  'end初始化类 '
" R( F+ m$ A+ d+ X$ v  ********************************************
' i3 O2 V; I% U% g+ W  '********************************************
# r5 `0 ^" V! c! U! G  h8 m  'begin销毁类 9 P- w- ^  z. [7 [
  '******************************************** " b: S. R' }0 H
  Private Sub Class_Terminate() 2 r& z6 @* F. Y% s  a& E
  sBASE_64_CHARACTERS="" end sub - W& M( G* q, Y9 r: N
  '********************************************
# }: x4 x8 k7 Q! ^$ E% Z9 \  'end销毁类 0 I0 r7 ^. }: l6 m
  '********************************************
/ u% ^7 k9 P( G8 D& X1 O. A  '********************************************
" |7 I  H% M4 ?  'begin将Ansi编码的字符串进行Base64编码
- @$ @* s" m8 [& @# ?" [( M$ e, T  '********************************************
+ S8 O; H! c1 R  public function Encode(paramString)
9 S" i5 k$ s  \$ W- B  tempString="" ! ?1 c) Z1 p' b. g% l
  returnValue=""
; d0 n. K% v, S6 n. |  lenString=len(paramString)
, i3 W" s& z7 r9 [" D* X+ G" u& t1 O  if lenString<1 then ( a, e: K7 K2 B: s7 s  \/ @
  Encode=returnValue
0 o8 f5 \! e4 L+ ^! f/ g, O  else
' K* P" T' l* r- l  mod3String=lenString mod 3 0 d" O8 _# B- D' ^5 T
  '补足位数是为了便于计算 ! T& G0 _7 o$ S7 D
  if mod3String>0 then 8 K9 W8 w: @, O8 r+ q
  lenString=lenString+3-mod3String
: d1 ]8 U3 c/ Y0 G9 C2 k: T" a4 v  lenString=lenString-3 " N6 J% a! i6 q* r1 b
  end if

返回列表