原创著作,产权保护 政府、投票、评选、公安、学校、问卷、视频会议专注发展中小企事业 系统报价 | 支付帐号 | 授权查证
    计算机著作版权登记号:2014SR032463 手机:+86-1373066-4304 | QQ:1213920482 欢迎选择智睿软件系统 欢迎选择智睿软件系统
智睿软件系统
ASP常用加密解密算法技术
来源:智睿 浏览:1471 次 发布时间:2020-06-17 08:49:11

1.ESCAPE加密与解密(支持中文)

<%
dim str,str2,str3
str = "asp"
str2 = escape(str) '加密
str3 = UnEscape(str2) '解密

Response.Write("原字符:"&str& "
")  
Response.Write("加密后:" &str2&"
")
Response.Write("解密后:" &str3&"
")
%>
BASE64编码解码(支持中文)


<%
Function Base64Encode(ByVal Str)
        dim Xml, Stream, Node, Encode
        Set Xml = Server.CreateObject("Msxml2.DOMDocument")
        Set Stream = Server.CreateObject("ADODB.Stream")
        Set Node = Xml.CreateElement("TmpNode")
        Node.DataType = "bin.base64"
        Stream.Charset = "UTF-8"
        Stream.Type = 2 '0 = AdStateClosed/1 = AdStateOpen
        Stream.Open()
        Stream.WriteText(Str)
        Stream.Position = 0
        Stream.Type = 1 '1=adTypeBinary/2=adTypeText
        Node.NodeTypedValue = Stream.Read(-1) '-1 = AdReadAll
        Stream.Close()
        Encode = Replace(Node.Text, Vblf, "")
        Encode = Replace(Encode, Vbcr, "")
        Base64Encode = Replace(Encode,"77u/","") 'base64编码后,比起.net多了77u/
        Set Node = Nothing
        Set Stream = Nothing
        Set Xml = Nothing
End Function

Function Base64Decode(ByVal Str)
        Dim Val
        With Server.CreateObject("Msxml2.DOMDocument").CreateElement("TmpNode")
                .DataType = "bin.base64"
                .Text = Str
                Val = .NodeTypedValue
        End With
        With Server.CreateObject("ADODB.Stream")
                .Type = 1
                .Open
                .Write Val
                .Position = 0
                .Type = 2
                .Charset = "UTF-8"
                Base64Decode = .ReadText(-1)
        End With
End Function

dim str,encode,newline
newline="
"
str= "asp学习"

encode = base64Encode(str)
response.write "加密前为:" & str & newline
response.write "加密后为:" & encode & newline
response.write "解密后为:" & base64Decode(encode) & newline
%>
ASP常用加密算法

ASP常用加密算法<%
Function Hash(HashType, Target)
On Error Resume Next

Dim PlainText

If IsArray(Target) = True Then PlainText = Target(0) Else PlainText = Target End If

With CreateObject("ADODB.Stream")
.Open
.CharSet = "Windows-1252"
.WriteText PlainText
.Position = 0
.CharSet = "UTF-8"
PlainText = .ReadText
.Close
End With

Set UTF8Encoding = CreateObject("System.Text.UTF8Encoding")
Dim PlainTextToBytes, BytesToHashedBytes, HashedBytesToHex

PlainTextToBytes = UTF8Encoding.GetBytes_4(PlainText)

Select Case HashType
Case "md5": Set Cryptography = CreateObject("System.Security.Cryptography.MD5CryptoServiceProvider") '< 64 (collisions found)
Case "ripemd160": Set Cryptography = CreateObject("System.Security.Cryptography.RIPEMD160Managed")
Case "sha1": Set Cryptography = CreateObject("System.Security.Cryptography.SHA1Managed") '< 80 (collision found)
Case "sha256": Set Cryptography = CreateObject("System.Security.Cryptography.SHA256Managed")
Case "sha384": Set Cryptography = CreateObject("System.Security.Cryptography.SHA384Managed")
Case "sha512": Set Cryptography = CreateObject("System.Security.Cryptography.SHA512Managed")
Case "md5HMAC": Set Cryptography = CreateObject("System.Security.Cryptography.HMACMD5")
Case "ripemd160HMAC": Set Cryptography = CreateObject("System.Security.Cryptography.HMACRIPEMD160")
Case "sha1HMAC": Set Cryptography = CreateObject("System.Security.Cryptography.HMACSHA1")
Case "sha256HMAC": Set Cryptography = CreateObject("System.Security.Cryptography.HMACSHA256")
Case "sha384HMAC": Set Cryptography = CreateObject("System.Security.Cryptography.HMACSHA384")
Case "sha512HMAC": Set Cryptography = CreateObject("System.Security.Cryptography.HMACSHA512")
End Select

Cryptography.Initialize()

If IsArray(Target) = True Then Cryptography.Key = UTF8Encoding.GetBytes_4(Target(1))

BytesToHashedBytes = Cryptography.ComputeHash_2((PlainTextToBytes))

For x = 1 To LenB(BytesToHashedBytes)
HashedBytesToHex = HashedBytesToHex & Right("0" & Hex(AscB(MidB(BytesToHashedBytes, x, 1))), 2)
Next

If Err.Number <> 0 Then Response.Write(Err.Description) Else Hash = LCase(HashedBytesToHex)

On Error GoTo 0
End Function

Response.Write(Hash("sha256HMAC","baidu.com"))

%>


【刷新页面】【加入收藏】【打印此文】 【关闭窗口】
上一篇:智睿政府网站管理系统 V 10.0.4 2 政府网站系统, 事业单位网站系统 下一篇:智睿公安公众信息管理系统 V 10.2.7 公安内网系统,公安信息系统