返回列表 发帖

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

class Base64Class
, p) u, \8 [/ y( d- Q3 k  rem Const 6 S- x4 F+ n3 A+ s2 ]) V5 o- M
  dim sBASE_64_CHARACTERS'转化码
! ~( t( L: C# d6 {  \  dim lenString '计算字符串的长度 5 o! b" P; x: j; [* J" m
  dim iCount '计数器
# x2 k. `% w) V+ u& z7 X  dim returnValue '返回值 % c, D) Z/ k  B: i7 Y
  dim tempChar'缓存字符
# _/ c( z7 i8 [: ]( H4 D: B  dim tempString'缓存字符串
6 X" ]6 G) D% J! q" x/ U  dim paramString '参数字符串
  z* S/ a, I% ?5 s5 ?  dim temHex'缓存缓存十六进制 7 u' w/ |( [4 W* v. s$ N2 o
  dim tempLow'缓存低位
' X% A3 b  p9 Y2 S* G, C  dim tempHigh'缓存高位
6 E+ u+ i' R4 D3 g  dim mod3String'
5 h" q* H. u5 `  dim mod4String'
4 H0 _7 @4 S# z; a( d9 m) x; I  dim tempBinary'
9 s3 l+ c4 q% H; g' C$ Z  dim tempByteOne' 3 J( B# j1 f* X
  dim tempByteTwo'
% {8 ~# v* ~# U& I6 \% R; s  dim tempByteThree' ; ?* M+ G4 u/ W- X
  dim tempByteFour'
' E4 D3 A. B  z$ s  dim tempSaveBitsOne' " F# E4 W8 A5 s% K) B; Z' u
  dim tempSaveBitsTwo' ) |8 |9 n5 Q! Z6 Z. X+ w* e9 M
  '********************************************! X2 J( u6 G5 n0 q5 F
  'begin初始化类
) {3 {3 M, @' o. w- U) c8 Y. ?  '********************************************
& a8 ~) X- Q2 n  private sub Class_Initialize() 1 U- A' S, }7 F8 y7 x( f, P
  sBASE_64_CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" end sub ( g" t; Z: W/ `* j. v
  '********************************************
3 D0 Q) \( h1 ?; d) G6 a$ L  'end初始化类 '5 {4 ~4 i& `! \2 K7 E. B
  ******************************************** 3 ?8 x0 `* f& E
  '******************************************** $ O+ `" z9 e6 j0 m" ]% o1 K
  'begin销毁类
( ?; X! k0 i. `7 B" |: K- d& M  '********************************************
+ ]2 J6 l% ?! z! G2 Z7 {: _. ?  Private Sub Class_Terminate()
7 f, a" E: n/ r* e+ B: a  sBASE_64_CHARACTERS="" end sub
3 v% g8 K- m5 D4 s( {$ j  '******************************************** 7 q1 t4 g8 Z( Y$ S7 Q: Q
  'end销毁类 " V3 y3 l2 q4 y0 X% C3 ]
  '********************************************2 y0 n( M3 A8 W
  '********************************************
; U1 P# O: Y+ o' l7 D* V3 J  'begin将Ansi编码的字符串进行Base64编码
9 m) I9 j: i2 i2 T  '******************************************** 1 {1 _- a3 [) m1 Q
  public function Encode(paramString)
3 s: {; R9 b* m  tempString="" 9 S& M4 q9 j: H
  returnValue="" 1 K5 s7 Q& B) [, m
  lenString=len(paramString)
- e4 c# c# h6 Y3 U  M% ~  M  if lenString<1 then ! g- x- J0 a, s" e6 M, H9 D
  Encode=returnValue   \  j& q( T9 B' Y
  else
( M" o- q% F- X5 x7 z  mod3String=lenString mod 3 ; H! S8 I7 M' U5 ?4 U) f
  '补足位数是为了便于计算 3 r. x: S! C& Y6 ~$ F7 M
  if mod3String>0 then
" G5 ]& q5 G  K# _; f  lenString=lenString+3-mod3String
+ `2 N+ P' _) s: I) g6 d: u  lenString=lenString-3
; S/ n9 y5 S# f) ]$ ?' {! p  end if

返回列表