① 求vb md5加解密
代码很多。仔细看先建一个类Class Mole 取名为ClsAPIMD5复制下面的代码到类里:'API 做的MD5类Option Explicit
Private Declare Function CryptAcquireContext Lib "advapi32.dll" _
Alias "CryptAcquireContextA" ( _
ByRef phProv As Long, _
ByVal pszContainer As String, _
ByVal pszProvider As String, _
ByVal dwProvType As Long, _
ByVal dwFlags As Long) As LongPrivate Declare Function CryptReleaseContext Lib "advapi32.dll" ( _
ByVal hProv As Long, _
ByVal dwFlags As Long) As LongPrivate Declare Function CryptCreateHash Lib "advapi32.dll" ( _
ByVal hProv As Long, _
ByVal Algid As Long, _
ByVal hKey As Long, _
ByVal dwFlags As Long, _
ByRef phHash As Long) As LongPrivate Declare Function CryptDestroyHash Lib "advapi32.dll" ( _
ByVal hHash As Long) As LongPrivate Declare Function CryptHashData Lib "advapi32.dll" ( _
ByVal hHash As Long, _
pbData As Any, _
ByVal dwDataLen As Long, _
ByVal dwFlags As Long) As LongPrivate Declare Function CryptGetHashParam Lib "advapi32.dll" ( _
ByVal hHash As Long, _
ByVal dwParam As Long, _
pbData As Any, _
pdwDataLen As Long, _
ByVal dwFlags As Long) As LongPrivate Const PROV_RSA_FULL = 1Private Const ALG_CLASS_HASH = 32768Private Const ALG_TYPE_ANY = 0Private Const ALG_SID_MD2 = 1
Private Const ALG_SID_MD4 = 2
Private Const ALG_SID_MD5 = 3
Private Const ALG_SID_SHA1 = 4Enum HashAlgorithm
md2 = ALG_CLASS_HASH Or ALG_TYPE_ANY Or ALG_SID_MD2
MD4 = ALG_CLASS_HASH Or ALG_TYPE_ANY Or ALG_SID_MD4
md5 = ALG_CLASS_HASH Or ALG_TYPE_ANY Or ALG_SID_MD5
SHA1 = ALG_CLASS_HASH Or ALG_TYPE_ANY Or ALG_SID_SHA1
End EnumPrivate Const HP_HASHVAL = 2
Private Const HP_HASHSIZE = 4Function HashString( _
ByVal Str As String, _
Optional ByVal Algorithm As HashAlgorithm = md5) As String
Dim hCtx As Long
Dim hHash As Long
Dim lRes As Long
Dim lLen As Long
Dim lIdx As Long
Dim abData() As Byte ' Get default provider context handle
lRes = CryptAcquireContext(hCtx, vbNullString, _
vbNullString, PROV_RSA_FULL, 0) If lRes <> 0 Then ' Create the hash
lRes = CryptCreateHash(hCtx, Algorithm, 0, 0, hHash) If lRes <> 0 Then ' Hash the string
lRes = CryptHashData(hHash, ByVal Str, Len(Str), 0) If lRes <> 0 Then
' Get the hash lenght
lRes = CryptGetHashParam(hHash, HP_HASHSIZE, lLen, 4, 0) If lRes <> 0 Then ' Initialize the buffer
ReDim abData(0 To lLen - 1) ' Get the hash value
lRes = CryptGetHashParam(hHash, HP_HASHVAL, abData(0), lLen, 0) If lRes <> 0 Then ' Convert value to hex string
For lIdx = 0 To UBound(abData)
HashString = HashString & _
Right$("0" & Hex$(abData(lIdx)), 2)
Next End If End If End If ' Release the hash handle
CryptDestroyHash hHash End If
End If ' Release the provider context
CryptReleaseContext hCtx, 0 ' Raise an error if lRes = 0
If lRes = 0 Then Err.Raise Err.LastDllErrorEnd FunctionFunction HashFile( _
ByVal Filename As String, _
Optional ByVal Algorithm As HashAlgorithm = md5) As String
Dim hCtx As Long
Dim hHash As Long
Dim lFile As Long
Dim lRes As Long
Dim lLen As Long
Dim lIdx As Long
Dim abHash() As Byte ' Check if the file exists (not the best method BTW!)
If Len(Dir$(Filename)) = 0 Then Err.Raise 53
' Get default provider context handle
lRes = CryptAcquireContext(hCtx, vbNullString, _
vbNullString, PROV_RSA_FULL, 0) If lRes = 0 And Err.LastDllError = &H80090016 Then
' There's no default keyset container!!!
' Get the provider context and create
' a default keyset container
lRes = CryptAcquireContext(hCtx, vbNullString, _
vbNullString, PROV_RSA_FULL, CRYPT_NEWKEYSET)
End If
If lRes <> 0 Then ' Create the hash
lRes = CryptCreateHash(hCtx, Algorithm, 0, 0, hHash) If lRes <> 0 Then ' Get a file handle
lFile = FreeFile
' Open the file
Open Filename For Binary As lFile
If Err.Number = 0 Then
Const BLOCK_SIZE As Long = 32 * 1024& ' 32K
ReDim abBlock(1 To BLOCK_SIZE) As Byte
Dim lCount As Long
Dim lBlocks As Long
Dim lLastBlock As Long
' Calculate how many full blocks
' the file contains
lBlocks = LOF(lFile) \ BLOCK_SIZE
' Calculate the remaining data length
lLastBlock = LOF(lFile) - lBlocks * BLOCK_SIZE
' Hash the blocks
For lCount = 1 To lBlocks
Get lFile, , abBlock
' Add the chunk to the hash
lRes = CryptHashData(hHash, abBlock(1), BLOCK_SIZE, 0)
' Stop the loop if CryptHashData fails
If lRes = 0 Then Exit For
Next ' Is there more data?
If lLastBlock > 0 And lRes <> 0 Then
' Get the last block
ReDim abBlock(1 To lLastBlock) As Byte
Get lFile, , abBlock
' Hash the last block
lRes = CryptHashData(hHash, abBlock(1), lLastBlock, 0)
End If
' Close the file
Close lFile
End If If lRes <> 0 Then
' Get the hash lenght
lRes = CryptGetHashParam(hHash, HP_HASHSIZE, lLen, 4, 0) If lRes <> 0 Then ' Initialize the buffer
ReDim abHash(0 To lLen - 1) ' Get the hash value
lRes = CryptGetHashParam(hHash, HP_HASHVAL, abHash(0), lLen, 0) If lRes <> 0 Then ' Convert value to hex string
For lIdx = 0 To UBound(abHash)
HashFile = HashFile & _
Right$("0" & Hex$(abHash(lIdx)), 2)
Next End If End If End If ' Release the hash handle
CryptDestroyHash hHash End If
End If ' Release the provider context
CryptReleaseContext hCtx, 0 ' Raise an error if lRes = 0
If lRes = 0 Then Err.Raise Err.LastDllErrorEnd Function
使用时:Private Sub Form_Load()
Dim mymd5 As New ClsAPIMD5
Dim md5str As String
md5str = mymd5.HashString(" test", md5)
Set mymd5 = Nothing '用完释放内存End Sub
② 谁知道怎么给文件加密啊
用这个软件,非常简单
文件加密解密系统 V2.2
下载地址
http://www.skycn.com/soft/7060.html
③ powerbuilder 可以调用DES64.dll 对字符串进行加密和解密,但是对加密密码的长度有限制,最多只能8位
网上找pb的信息现在不好找了,给你3种加密方法,已发信箱。
都是用过的,能用
④ 简述入侵检测常用的四种方法
入侵检测系统所采用的技术可分为特征检测与异常检测两种。
1、特征检测
特征检测(Signature-based detection) 又称Misuse detection ,这一检测假设入侵者活动可以用一种模式来表示,系统的目标是检测主体活动是否符合这些模式。
它可以将已有的入侵方法检查出来,但对新的入侵方法无能为力。其难点在于如何设计模式既能够表达“入侵”现象又不会将正常的活动包含进来。
2、异常检测
异常检测(Anomaly detection) 的假设是入侵者活动异常于正常主体的活动。根据这一理念建立主体正常活动的“活动简档”,将当前主体的活动状况与“活动简档”相比较,当违反其统计规律时,认为该活动可能是“入侵”行为。
异常检测的难题在于如何建立“活动简档”以及如何设计统计算法,从而不把正常的操作作为“入侵”或忽略真正的“入侵”行为。
(4)pbmd5加密解密方法扩展阅读
入侵分类:
1、基于主机
一般主要使用操作系统的审计、跟踪日志作为数据源,某些也会主动与主机系统进行交互以获得不存在于系统日志中的信息以检测入侵。
这种类型的检测系统不需要额外的硬件.对网络流量不敏感,效率高,能准确定位入侵并及时进行反应,但是占用主机资源,依赖于主机的可靠性,所能检测的攻击类型受限。不能检测网络攻击。
2、基于网络
通过被动地监听网络上传输的原始流量,对获取的网络数据进行处理,从中提取有用的信息,再通过与已知攻击特征相匹配或与正常网络行为原型相比较来识别攻击事件。
此类检测系统不依赖操作系统作为检测资源,可应用于不同的操作系统平台;配置简单,不需要任何特殊的审计和登录机制;可检测协议攻击、特定环境的攻击等多种攻击。
但它只能监视经过本网段的活动,无法得到主机系统的实时状态,精确度较差。大部分入侵检测工具都是基于网络的入侵检测系统。
3、分布式
这种入侵检测系统一般为分布式结构,由多个部件组成,在关键主机上采用主机入侵检测,在网络关键节点上采用网络入侵检测,同时分析来自主机系统的审计日志和来自网络的数据流,判断被保护系统是否受到攻击。
⑤ java的sha1加密和object-c的sha1加密后的值不一样,谁能帮我解决一下。多谢了
结果是一样的, 但是你多搞了一点: java你是用Base64编码成字符串, 而ObjC你是直接用16进制输出的, 你java上不Base64编码, 也输出成16进制, 就一样了;