返回列表 发帖

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

class Base64Class
7 A: @4 Q; }& e4 ^  rem Const 3 S. @  m  X: \! D
  dim sBASE_64_CHARACTERS'转化码 - K9 J& w* l3 _7 Y: G& }: k7 O- v
  dim lenString '计算字符串的长度
6 |* U4 L: \' w* q1 Q( G. M  dim iCount '计数器
1 G5 n$ M; p- ~. s1 a+ }  dim returnValue '返回值
; |# u* X) E3 T4 Q& r0 i2 }7 w  dim tempChar'缓存字符
3 l- j/ H, r) r2 R( F; P$ Z  dim tempString'缓存字符串 : W, |- L/ F3 s+ c
  dim paramString '参数字符串
- _+ J, J& g+ i3 O7 P5 Y6 a  dim temHex'缓存缓存十六进制 ! A/ }, n2 V# a* N( A6 V
  dim tempLow'缓存低位 % X* u/ `7 g! I. d$ {
  dim tempHigh'缓存高位 2 p: r  q9 H* }  U
  dim mod3String'
$ e; M# C3 I) g  dim mod4String' ( m- h, J) c  Y/ }
  dim tempBinary' & I* C$ G6 q) h4 }7 l
  dim tempByteOne' : Q' ^# l2 J3 |2 p5 F
  dim tempByteTwo' " V% |. i/ u" i0 {* V4 e
  dim tempByteThree' 0 I# O$ w  Z: h) ?  D, z' T* f8 w
  dim tempByteFour'
, D' `- h9 L+ C+ ?: y  dim tempSaveBitsOne' 0 C3 l2 C5 z- L7 U3 E
  dim tempSaveBitsTwo'
) w1 i( O$ M2 k2 Q  '********************************************
# E5 K2 }9 c& |: X6 v  'begin初始化类 0 Q3 g& L3 d: L0 P2 m! `% Y+ [$ }
  '********************************************
; _5 x- S& D4 l8 Y2 {: y' I3 o! U  private sub Class_Initialize()
( P4 V9 E% h5 T  r) M) V  sBASE_64_CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" end sub
3 t# r( f1 q5 b0 R. g  '********************************************   e/ L( e: \/ T3 C9 H* y
  'end初始化类 '0 L# `7 w* [5 V/ o, p
  ********************************************
1 H0 f, }3 s  @) t6 d0 b* v+ p6 w  '******************************************** 6 F- ]" P! O6 u* T+ Z" p. W8 C
  'begin销毁类
( y9 c# Y4 c/ D$ {# E  '******************************************** ( J+ W6 N$ \4 c9 y6 ~6 N
  Private Sub Class_Terminate() 4 N2 J: ~7 K0 o- Z; E# |# Z
  sBASE_64_CHARACTERS="" end sub % @+ d' |% n6 q# `' L; C; a
  '********************************************
; E: ?6 v! K# v# x+ `7 H  'end销毁类
0 o" m4 i; T% q' q8 M  '********************************************
- h& l' r- [& b/ d  '********************************************
5 u7 z+ _% ?& c( Y  'begin将Ansi编码的字符串进行Base64编码
) r  ]6 a8 ^! r( ?$ [  '********************************************
1 J2 [+ T& i- f' q  public function Encode(paramString)
( u- r7 ^' a4 }+ Q. f  tempString="" ! }; E& C0 n' d
  returnValue=""
+ m' c" ?, l. p/ w  lenString=len(paramString)
3 q! p1 W; ?5 d' L$ a' d  if lenString<1 then / L  x/ B, w6 B! |9 C$ }) Y8 v
  Encode=returnValue
/ B4 y5 U8 V1 t  else
- @8 ]$ ~# T1 z; c7 d6 @  mod3String=lenString mod 3 ) t' \9 u! s! t; C$ ]) W0 U0 O
  '补足位数是为了便于计算 . o* O( x5 E4 _* |) z
  if mod3String>0 then
0 {; c3 `- P: d1 u9 k' N, u" M  lenString=lenString+3-mod3String
! h  K8 u) c9 B. z# S. ]  lenString=lenString-3   i6 u& q: @4 Z
  end if

返回列表