比如加密后保存不希望被别人(管理员)看到的信息。
请回复,谢谢!!!
---------------------------------------------------------------
以下是我从网上下的,你自己看看,应该对你有用:)
--------------------------------------------------------------------------------
Introduction
Do you have a website where users need to login, and when they do you compare the password they enter with a column in a usertable? Some people do logins like this. It's easy to program and it works just fine. But what if someone got hold of the usertable and all the passwords of everyone? You may want to hide or encrypt the passwords in the usertable. Many programming languages have functions to do this. I make ASP-webpages, and I haven't found any quick functions to do this. There are plenty of components to do this, some free of charge even. But what if you cant install components on the webserver
Here is a short and neat way to encrypt your users passwords. You need two strings for it to work. Typically the username and the password.
Code
Function encrypt(x1, x2)
s = ""
t = 0
For i = 1 to len(x1)
t = t + asc(mid(x1,i,1))
Next
If t>598 Then t = t mod 598
For i = 1 to len(x2)
y = (t + asc(mid(x2,i,1)) * asc(mid(x2,((i+1) mod len(x2)+1),1))) mod 255
s = s & chr(y)
Next
For i = (len(x2) + 1) to 10
y = t^3*i mod 255
s = s & chr(y)
Next
encrypt = s
End Function
End Function
If you want to test this function you can create an asp-page and upload it to your website. Here's my codelisting to encrypt.asp
1
2Function encrypt(x1, x2)
3s = ""
4t = 0
5For i = 1 to len(x1)
6t = t + asc(mid(x1,i,1))
7Next
8If t>598 Then t = t mod 598
9For i = 1 to len(x2)
10y = (t + asc(mid(x2,i,1)) * asc(mid(x2,((i+1) mod len(x2)+1),1))) mod 255
11s = s & chr(y)
12Next
13For i = (len(x2) + 1) to 10
14y = t^3*i mod 255
15s = s & chr(y)
16Next
17encrypt = s
18End Function
1<html>
2<head>
3<title>Encrypt</title>
4</head>
5<body>
If request.form("name") = "" Then
1<form action="encrypt.asp" method="post">
2<input name="name" type="text"/><input name="pass" type="text"/>
3<input type="submit"/>
4</form>
Else
response.write encrypt(request.form("name"),request.form("pass"))
End If
1</body>
2</html>
Remarks
The function is not reversible, so there is no way to take the result and reverse it into the password. You will need to recreate the password with a new one (some users seem to forget their passwords and always wants it retreieved)
This is not a high-level encryption, but its good enough to hide it from lame hackers (hehe).
The password is always sent from the user inputpage to the page encrypting it. Somewhere in between a hacker can fetch it. Secure zones (SSL) can remedy this.
Feel free to use the code to whatever you like. But if you alter it make a post in the thread related to this article so we all can share the fun.
About tommy skaue
-------------------------------------------------------------------
慢慢看看吧!呵呵!
这个例子是只有加密,没有解密过程的!
我还有一个思路,就是你在用户自己设定的密码后边加上几个随机字符
比如说加上4位
password1 *******5897
这里5897可是随即产生的。
你只要取出 left(password1,len(password1)-4)
就可以啦!
这个方法比较简便!
---------------------------------------------------------------
function encrypt(ecode)
Dim texts
dim i
for i=1 to len(ecode)
texts=texts & chr(asc(mid(ecode,i,1))+i)
next
encrypt = texts
end function
function decrypt(dcode)
dim texts
dim i
for i=1 to len(dcode)
texts=texts & chr(asc(mid(dcode,i,1))-i)
next
decrypt=texts
end function
function mistake(preString)
Dim texts
Dim seed
Dim i,length
prestring = trim(preString)
length = len(preString)
seed = length
Randomize(length)
texts = ""
for i = 1 to length
seed = int(94rnd(-asc(mid(preString,i,1))-seedasc(right(prestring,1)))+32)
texts = texts & chr(seed) & chr(int(94*rnd(-seed)+32))
next
dim dist
dist=""
for i = 1 to len(texts)
if mid(texts,i,1)<>"'" then
dist=dist+mid(texts,i,1)
end if
next
mistake = dist
end function
---------------------------------------------------------------
你用微软的script encode加密
Script Encoder 下载地址:
http://msdn.microsoft.com/scripting/vbscript/download/x86/sce10en.exe
SCRENC.EXE这是一个运行在DOS PROMAPT的命令工具,它使脚本设计者可以对最终的脚本进行编码,从而使 Web 主机和 Web 客户不能查看或修改它们的源代码。不过有一点需要注意的是加密后的程序要求用户的游览器必须使用Internet Explorer 5.0以上的版本。加完密后的脚本变成类似于如下的内容:
脚本加密程序只对脚本代码进行加密,文件的其他内容不动且以普通文本形式显示。要使用脚本加密程序,以通常方法对文本进行开发和调试,然后使用该实用程序对最终的脚本进行加密。 脚本加密程序在源代码中使用标记来标识加密开始的位置。
对于 Visual Basic Scripting Edition (VBScript),如下示例显示了如何使用编码标记来显示普通文本的版权信息:
示例
如下是使用脚本加密程序的一个例子以及对其结果的简单解释:
对输入文件 test.html 进行加密,生成输出文件 encode.html,使用:
screnc test.html encode.html
对输入文件 test.htm 进行加密,并用编码后的输出文件覆盖输入文件,使用:
screnc /f test.htm
对当前目录中的所有 .ASP 文件进行加密,并把编码后的输出文件放在c:\temp中,使用:
screnc *.asp c:\temp
对当前目录中的所有 .ASP 文件进行加密,并把编码后的输出文件放在c:\temp中,使用:
screnc /e asp . c:\temp
对输入文件 test.htm 进行加密,并生成输出文件 encode.htm,确保没有指定语言属性的脚本块使用 VBScript,使用:
screnc /l vbscript test.htm encode.htm
对当前目录中的所有脚本小程序文件进行加密,并不经信息显示就用编码后的文件覆盖这些文件,使用:
screnc /s /f *.sct
要点 :经过编码后,如果您改动加密后的文本,哪怕只改动一个字。脚本的完整性就会丢失,从而不能再使用。
---------------------------------------------------------------
这是有名的MD5加密函数::代码如下::
<%
Private Const BITS_TO_A_BYTE = 8
Private Const BYTES_TO_A_WORD = 4
Private Const BITS_TO_A_WORD = 32
Private m_lOnBits(30)
Private m_l2Power(30)
Private Function LShift(lValue, iShiftBits)
If iShiftBits = 0 Then
LShift = lValue
Exit Function
ElseIf iShiftBits = 31 Then
If lValue And 1 Then
LShift = &H80000000
Else
LShift = 0
End If
Exit Function
ElseIf iShiftBits < 0 Or iShiftBits > 31 Then
Err.Raise 6
End If
If (lValue And m_l2Power(31 - iShiftBits)) Then
LShift = ((lValue And m_lOnBits(31 - (iShiftBits + 1))) * m_l2Power(iShiftBits)) Or &H80000000
Else
LShift = ((lValue And m_lOnBits(31 - iShiftBits)) * m_l2Power(iShiftBits))
End If
End Function
Private Function RShift(lValue, iShiftBits)
If iShiftBits = 0 Then
RShift = lValue
Exit Function
ElseIf iShiftBits = 31 Then
If lValue And &H80000000 Then
RShift = 1
Else
RShift = 0
End If
Exit Function
ElseIf iShiftBits < 0 Or iShiftBits > 31 Then
Err.Raise 6
End If
RShift = (lValue And &H7FFFFFFE) \ m_l2Power(iShiftBits)
If (lValue And &H80000000) Then
RShift = (RShift Or (&H40000000 \ m_l2Power(iShiftBits - 1)))
End If
End Function
Private Function RotateLeft(lValue, iShiftBits)
RotateLeft = LShift(lValue, iShiftBits) Or RShift(lValue, (32 - iShiftBits))
End Function
Private Function AddUnsigned(lX, lY)
Dim lX4
Dim lY4
Dim lX8
Dim lY8
Dim lResult
lX8 = lX And &H80000000
lY8 = lY And &H80000000
lX4 = lX And &H40000000
lY4 = lY And &H40000000
lResult = (lX And &H3FFFFFFF) + (lY And &H3FFFFFFF)
If lX4 And lY4 Then
lResult = lResult Xor &H80000000 Xor lX8 Xor lY8
ElseIf lX4 Or lY4 Then
If l