怎样给文件加密最安全?_编程10000问

<%@ 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

%>

 <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

时间: 2024-07-31 11:33:25

怎样给文件加密最安全?_编程10000问的相关文章

如何对文件进行操作?_编程10000问

<%@ LANGUAGE="VBScript" %> <% 'Set file i/o constants.  Const ForReading  = 1  Const ForWriting  = 2  Const ForAppending = 8  filename = "test.txt"  path = Server.MapPath("data") & "\" & filename<

可以在线创建文件夹吗?_编程10000问

folder.htm<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> <html> <head> <title>闪亮日子之在线创建文件夹</title> </head> <body> 春风精彩<br> 在线创建文件夹</td>   <tr>     <td h

如何限制上传文件的大小?_编程10000问

 <%@ LANGUAGE="VBscript" %>      <html><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> <head>      <title>撼雪喷云之限传文件</title>      </head>      <body>      <

如何用Access加密页面?_编程10000问

<%userid = Request("userid")userpass = Request("userpass") Set conn = Server.CreateObject("ADODB.Connection")DBPath = Server.MapPath("userinfo.mdb")conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq=&qu

如何创建Word文件?_编程10000问

creatdoc.asp<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> <!DOCTYPE html PUBLIC "-//W3C/Dtd html 3.2 Final//EN"><head><title>星河影动之创建Word文件</title><META HTTP-EQUIV="Re

如何用ASP输出HTML文件?_编程10000问

<!--#include file="top.inc"--><%u_title=request.form("u_title")<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> ' 检查标题是否被输入.if u_title = "" then%><form method="P

如何一行行地读取文件?_编程10000问

dim input(30) <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> ' 定义一个数组,大小可随时更改.这里为了显示方便. file_path=Server.Mappath("index.html") Set fs=Server.CreateObject("Scripting.FileSystemObject") Set f

如何计算下载一个文件需要多长时间?_编程10000问

<%Function DownloadTime(intFileSize, strModemType)Dim TimeInSeconds, ModemSpeed, strDownloadTime, AppendStringDim intYears, intWeeks, intDaysDim intHours, intMinutes, intSecondsintYears = 0intWeeks = 0intDays = 0intHours = 0intMinutes = 0intSeconds =

为什么用磁盘序列号加密过的代码不能被复制安装?_编程10000问

default.asp<html><head><title>星河影动之磁盘序列号加密代码存取管理</title></head><% dim conn,fs,fSet conn = Server.CreateObject("ADODB.Connection")conn.open "driver={Microsoft Access Driver (*.mdb)};uid=;pwd=3302;dbq="&a