返回列表 发帖

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

class Base64Class
+ Y1 S! W' O: m* I7 }& K  rem Const & B) y& n; J9 d: m) S% M, _& G
  dim sBASE_64_CHARACTERS'转化码 . q1 ~: I$ u" H9 I& J7 C$ a
  dim lenString '计算字符串的长度
; @8 ~; A8 ^9 k  dim iCount '计数器 7 g" u7 @3 P8 ^. u- G
  dim returnValue '返回值
/ o* I/ }- q- t: @  dim tempChar'缓存字符 , M! P2 v- Y% |) ?
  dim tempString'缓存字符串 3 I2 ?9 B7 {/ ^
  dim paramString '参数字符串 3 C3 p% I/ l' I% t; L% J
  dim temHex'缓存缓存十六进制 / |5 V& ?, x' e/ h! p
  dim tempLow'缓存低位
: Q) ^' P! r$ p$ f  dim tempHigh'缓存高位 9 Q% V9 X7 Q, u9 Z- o3 ]
  dim mod3String' " F; t9 d4 R0 I( R( q: N9 m! _
  dim mod4String' 1 D8 ], A4 L% J
  dim tempBinary'
! R9 c3 l( M$ |  dim tempByteOne'
- S: y' F9 @1 P) U& x* Z  dim tempByteTwo' 5 s0 h3 }3 {0 o  G5 V" ^. I
  dim tempByteThree'
& _. k! {* w+ v& j  dim tempByteFour'   j8 `8 p9 G6 Z7 O; @& O- r0 w
  dim tempSaveBitsOne'
+ E0 U! x  ~6 _6 ~/ S% s  dim tempSaveBitsTwo' 7 Y4 [0 r2 ?& C* E% F* z& s
  '********************************************
! J: }9 I. l: o) l$ o  'begin初始化类 ; C+ l; R& L  R5 l; \6 g
  '********************************************
& Z& t- J8 R  v( Y, L% H  private sub Class_Initialize()
+ n* _3 q3 f) m$ v0 @& a  sBASE_64_CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" end sub
; v/ _" z7 o* g! Z' c1 s7 l  '******************************************** - G" w  r1 z+ F3 [
  'end初始化类 '3 n9 e1 G) V/ E" T. M8 b( P2 ~" s6 }
  ********************************************
% L8 @' U8 r6 g) ?8 D+ @  '******************************************** - `8 l6 F' T& V
  'begin销毁类
0 x" z5 y- O3 j3 X0 \; L+ Z# l  U  '********************************************
. n( x* w2 k3 |& Z  Private Sub Class_Terminate() 0 T8 @. X* U, @0 K( k
  sBASE_64_CHARACTERS="" end sub
9 ~% v5 e$ k$ `7 J. [( x; `6 W  '********************************************
6 q0 S7 }. L/ g, x  'end销毁类 9 `7 ~' u. A7 A# X1 w! p* _
  '********************************************+ V' @/ u7 F, N2 Q( z: W& g& a4 }) c
  '******************************************** 9 r/ a/ A" Z) z  C1 x0 ?* Z1 E
  'begin将Ansi编码的字符串进行Base64编码
1 k6 Y0 N7 \; R+ P" g  '********************************************
. {+ \2 W8 }3 O  public function Encode(paramString)
$ e7 l) a7 I' P; r0 M  tempString=""
: |2 u, B  S. b8 d' U" k) R  returnValue="" 4 [$ w- Q+ v- T0 n- b
  lenString=len(paramString) . D# J# b4 ?$ ^; |/ l
  if lenString<1 then 8 I- u. s- N; H! ^( `6 m9 Y
  Encode=returnValue
& {* g- ]6 V  {  else
3 O8 w0 D' P7 n. t8 p" m  mod3String=lenString mod 3
) L( _& S$ \6 `' j1 c( V  '补足位数是为了便于计算
3 W) @6 V5 s4 p% m  if mod3String>0 then 1 _+ W7 Y' ?( T! _( J
  lenString=lenString+3-mod3String   r& C4 N) T# o3 L7 ~! V0 [
  lenString=lenString-3
5 i4 X" b$ `+ c' x- [; _- k; v  end if

返回列表