返回列表 发帖

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

class Base64Class
& ]( l* P2 l3 P0 o  rem Const
4 J8 v# b) L5 \" P  \  dim sBASE_64_CHARACTERS'转化码 2 [6 |- T( a5 w+ Y7 ]  ~
  dim lenString '计算字符串的长度 * ?& ]/ |, g, |
  dim iCount '计数器 ; ~4 M* v3 w; v4 Z3 U
  dim returnValue '返回值
! U' I" Q0 X/ ?8 K; [  dim tempChar'缓存字符
5 R. K+ W! ^9 f6 y  dim tempString'缓存字符串
' V& q: V3 f* _' b  dim paramString '参数字符串
# X& W0 m8 [3 i( K+ a: V  dim temHex'缓存缓存十六进制
: c7 O  r8 c% c3 ^  dim tempLow'缓存低位
7 Z* v; U2 R. Z& J  dim tempHigh'缓存高位 ) R4 x; {% I5 X2 W7 z- p, ]$ ?
  dim mod3String'
) Q7 f1 I1 m, `5 o6 d  dim mod4String'
8 G: i7 k2 ~" x  t  dim tempBinary'
" ~( l- G" H( N6 L" A  dim tempByteOne'
7 W( e, |3 f+ p3 o: d; }1 a: f  dim tempByteTwo'
( s/ q9 f2 v) s  \. C  dim tempByteThree'
$ h1 u( I5 F& }% Y* D. [$ M  dim tempByteFour'
4 M. X# A5 X$ s  dim tempSaveBitsOne'
; |) h) o9 s, \. q  h  dim tempSaveBitsTwo'
* P' A. s7 W- i; n+ q( s  '********************************************
! m: H, _% J0 ?  'begin初始化类 ) t) s& {  `0 C) [5 p
  '******************************************** 9 f- x6 b. T# A. {  e
  private sub Class_Initialize() ' Y; z0 `' [# b  m, m4 d* ^
  sBASE_64_CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" end sub
3 y  \- \6 K' Q) r$ I- d6 [  '******************************************** " a3 H" Y' t5 [) w: `  _& `! c
  'end初始化类 '1 s) I1 B/ G) q8 k5 L: g- ?: w3 H
  ******************************************** 4 V2 [8 ~: @& r$ S  c. \: p: A6 X
  '******************************************** 7 n/ s" B. m( z  ~, x+ g' g
  'begin销毁类
* I+ ?  G5 n) D/ u- B$ ~  '********************************************
/ \) `9 w" W/ q$ R7 M  Private Sub Class_Terminate() $ r% S) n) J: ]/ J0 m
  sBASE_64_CHARACTERS="" end sub
3 i' F) d4 \, b0 f3 h  '******************************************** 9 L' @6 H1 Z6 M4 F& ~6 L
  'end销毁类
) {3 C. @) r, O& W4 D, U( f# z  '********************************************
5 }% M1 q7 U, l7 J! t# n( c  '******************************************** " ]" n' F. s( {: v! K; ^+ E; Y0 @; i9 j* I
  'begin将Ansi编码的字符串进行Base64编码
/ r( E/ K# w- Q0 a6 l) w, r  '********************************************
0 l# f5 @: X, @( x, N7 x. O. h" J* k  public function Encode(paramString) ; a9 F7 M/ l8 i6 H9 Y
  tempString=""
( o2 o5 U5 J3 [5 c4 y  returnValue=""
+ E3 Z1 ]. I) |" Z7 l* K6 p" _9 W  lenString=len(paramString) 3 C  `) o9 g; \
  if lenString<1 then
) |7 S- W. Q: l, A4 c8 ]  Encode=returnValue
' q; [. y6 e- K, V  else
5 A0 F* Q: H$ ^! ]0 c3 A# \  mod3String=lenString mod 3 - W. l6 \. r9 ?% l
  '补足位数是为了便于计算
6 m5 e# F  p% C  if mod3String>0 then 6 _  k9 D  [: T& g. U# j
  lenString=lenString+3-mod3String % ]; C: \" b! `" e1 E7 W: t
  lenString=lenString-3
- p$ L5 Q9 C, |, ~  end if

返回列表