欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

怎样给文件加密最安全?

程序员文章站 2023-01-25 17:52:33
<%@ language = vbscript%><%response.expires = 0...

<%@ language = vbscript%>
<%

response.expires = 0


p = "abcdefg"
set testpwd = new cpassword
testpwd.enpwd p
testpwd.unpwd testpwd.showpwd(true)

k = testpwd.showpwd(true)
l = testpwd.showpwd(false)
set testpwd = nothing

with response
.write "
原文:" & p & "<br>"
.write "
加密后:" & k & "<br>"
.write "
解密后:" & l & "<br>"
end with


class cpassword
private cenpwd,cunpwd

private function my_hex(my_hex_source)
  my_hex = hex(my_hex_source)
  if len(my_hex) = 1 then
   my_hex = "0" & my_hex
  end if
end function

private function my_unhex(my_unhex_source)
  if len(my_unhex_source) = 2 then
   temp_value = my_hexreplace(left(my_unhex_source,1))
  end if
  my_unhex = temp_value * 16 + my_hexreplace(right(my_unhex_source,1))
end function

private function my_hexreplace(my_hexreplace_source)
  if asc(my_hexreplace_source) > 64 then
   my_hexreplace = asc(ucase(my_hexreplace_source)) - 55
  else
   my_hexreplace = asc(my_hexreplace_source) - 48
  end if
end function

public property get showpwd(enp)

' 输出.
  if enp then
   showpwd = cenpwd
  else
   showpwd = cunpwd
  end if
end property

sub enpwd(enpwd_source)
  if enpwd_source = "" then
   cenpwd = 0
   exit sub
  else
   randomize
   key = rnd * 256
   while key = 0
    key = rnd * 256
   wend
   for i=1 to len(enpwd_source)
    temp_string = key xor asc(mid(enpwd_source,i,1))
    crc = crc + temp_string
    cenpwd = cenpwd + my_hex(temp_string)
   next
   cenpwd = my_hex(key) + strreverse(cenpwd) + my_hex(crc mod 256)
  end if
end sub

sub unpwd(unpwd_source)
  if len(unpwd_source) < 6 or len(unpwd_source) mod 2 = 1 then
   cunpwd = 0
   exit sub
  end if
  old_key = my_unhex(left(unpwd_source,2))
  old_crc = my_unhex(right(unpwd_source,2))
  old_string = strreverse(mid(unpwd_source,3,len(unpwd_source)-4))
  for i=1 to len(old_string) - 1 step 2
   temp_value = my_unhex(mid(old_string,i,2))
   crc_temp = crc_temp + temp_value
   temp_string = temp_string + chr(temp_value xor old_key)
  next
  if old_crc <> (crc_temp mod 256) then
   cunpwd = 403
   exit sub
  end if
  cunpwd = temp_string
end sub
end class

%>