首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

100分求 DES加密/解密 算法的函数或Dll,能在VB中的实现!该如何解决

2012-01-31 
100分求 DES加密/解密 算法的函数或Dll,能在VB中的实现!今天在网上搜索了一个下午,没找到理想的.向各位XDJ

100分求 DES加密/解密 算法的函数或Dll,能在VB中的实现!
今天在网上搜索了一个下午,没找到理想的.

向各位XDJM求一个   现成的,稳定的   DES加密/解密算法的函数或Dll都可以.

我的邮箱:   saikoo@163.com  

先谢了!

[解决办法]
search "Large Archive of Cryptographic Algorithms "

A Source Code at:

http://www.freevbcode.com/ShowCode.Asp?ID=3779

没有测试。

[解决办法]
http://topic.csdn.net/t/20050706/12/4126283.html
[解决办法]
例子:

http://www.m5home.com/bbs/dispbbs.asp?boardID=2&ID=1445&page=2

类模块:

http://www.m5home.com/bbs/dispbbs.asp?boardID=10&ID=1448&page=1
[解决办法]
这种东西遍地都是。我曾下载了 DES C 代码实现,用它做过一个 DLL。后来又下载了一个类模块,改改代码,将对 ASCII 码加密改为对 Hex 串加密,也很好用。其实自己写一个也不难。
[解决办法]
'************************************************************************
'*
'*
'* DES/3DES 加解密类模块 V1.0
'*
'* 开发:张新扬
'* 2005.08.24
'*
'*
'************************************************************************



'
'======= 私有变量 =======

Private ip(63) As Byte, ip_1(63) As Byte, e(47) As Byte '数据变换
Private pc_1(55) As Integer, pc_2(47) As Integer, ccmovebit(15) As Integer '密钥生成
Private p(31) As Byte, ss(7, 3, 15) As Byte 'S变换
Private key_n1(15, 7) As Byte '密钥1
Private key_n2(15, 7) As Byte '密钥2

'
'======= API =========
Private Declare Sub CopyMemory Lib "kernel32 " Alias "RtlMoveMemory " (Destination As Any, Source As Any, ByVal Length As Long)


'
'***************************************************************
'
'==================== 下面是类的函数及方法 ===================
'
'***************************************************************






'==========================================================================================
' SetKey 函数说明:
' 设置3DES加/解密的密钥
' 返回:
' 无
' 参数:
' K_Bit() AS Byte 密钥,不少于16个元素
'==========================================================================================
Sub SetKey(K_Bit() As Byte)
Dim Key() As Byte
Dim K_Bit1(7) As Byte
Dim K_Bit2(7) As Byte

Key = K_Bit
ReDim Preserve Key(15) As Byte


CopyMemory K_Bit1(0), Key(0), 8
CopyMemory K_Bit2(0), Key(8), 8

'//根据密钥生成16个子密钥
GenSubKey K_Bit1(), key_n1()
GenSubKey K_Bit2(), key_n2()
End Sub


'==========================================================================================
' SetKey1 函数说明:
' 设置3DES加/解密的的第一个密钥
' 返回:
' 无
' 参数:
' K_Bit() AS Byte 密钥,不少于8个元素
'==========================================================================================
Sub SetKey1(K_Bit() As Byte)
'//根据密钥生成16个子密钥
Dim Key() As Byte
ReDim Preserve Key(7) As Byte


GenSubKey Key(), key_n1()
End Sub




[解决办法]
感谢fxy_2002(阿勇) 提供的源代码。我已测试通过。
但阿勇tx的使用有错误, 
cdes类在加解密前要调用setkey函数设置密码。
SetKey mm

Encrypt3Des_ArrToArr m_bit, e_bit, bFlag
[解决办法]
直接使用微软的加解密API,声明如下:
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 Long
Private Declare Function CryptReleaseContext Lib "advapi32.dll" (ByVal hProv As Long, ByVal dwFlags As Long) As Long
Private Declare Function CryptCreateHash Lib "advapi32.dll" (ByVal hProv As Long, ByVal Algid As Long, ByVal hSessionKey As Long, ByVal dwFlags As Long, ByRef phHash As Long) As Long
Private Declare Function CryptHashData Lib "advapi32.dll" (ByVal hHash As Long, ByVal pbData As String, ByVal dwDataLen As Long, ByVal dwFlags As Long) As Long
Private Declare Function CryptGetHashParam Lib "advapi32.dll" (ByVal hHash As Long, ByVal dwParam As Long, ByVal pbData As String, ByRef pdwDataLen As Long, ByVal dwFlags As Long) As Long
Private Declare Function CryptDestroyHash Lib "advapi32.dll" (ByVal hHash As Long) As Long
Private Declare Function CryptDeriveKey Lib "advapi32.dll" (ByVal hProv As Long, ByVal Algid As Long, ByVal hBaseData As Long, ByVal dwFlags As Long, ByRef hSessionKey As Long) As Long
Private Declare Function CryptEncrypt Lib "advapi32.dll" (ByVal hSessionKey As Long, ByVal hHash As Long, ByVal Final As Long, ByVal dwFlags As Long, ByVal pbData As String, ByRef pdwDataLen As Long, ByVal dwBufLen As Long) As Long
Private Declare Function CryptDecrypt Lib "advapi32.dll" (ByVal hSessionKey As Long, ByVal hHash As Long, ByVal Final As Long, ByVal dwFlags As Long, ByVal pbData As String, ByRef pdwDataLen As Long) As Long
Private Declare Function CryptDestroyKey Lib "advapi32.dll" (ByVal hSessionKey As Long) As Long
Private Declare Function CryptImportKey Lib "advapi32.dll" (ByVal hProv As Long, ByVal pbData As String, ByVal dwDataLen As Long, ByVal hPubKey As Long, ByVal dwFlags As Long, ByRef phKey As Long) As Long
Private Declare Function CryptExportKey Lib "advapi32.dll" (ByVal hSessionKey As Long, ByVal hExpKey As Long, ByVal dwBlobType As Long, ByVal dwFlags As Long, ByVal pbData As String, ByRef pdwDataLen As Long) As Long
Private Declare Function CryptGenRandom Lib "advapi32.dll" (ByVal hProv As Long, ByVal dwLen As Long, ByVal pbBuffer As String) As Long
该套API支持DES,LZ可以随便写一个上述API名称再加上DES关键GOOGLE一下即可,虽然大多是VC的,但不难改成VB版。

热点排行