这边有用VB调用DLL的例子,但是我不懂VB那位翻译一下,谢谢!!(150分)

P

popboy

Unregistered / Unconfirmed
GUEST, unregistred user!
Here is a Microsoft Word do
cument that contains the following Visual Basic for Applications code to illustrate the use of the AES Dynamic Link Library. Very similar code should also work in Visual Basic.

Private Const BlkLenMax = 32 ' maximum block length in bytes
Private Const KeyLenMax = 32 ' maximum block length in bytes
Private Const KeySchLenMax = 128 ' maximum key schedule length in bytes
Private BlkLen As Integer ' actual block length
Private KeyLen As Integer ' actual key length
Private Type AESctx ' Type to hold the AES context data
Ekey(0 To KeySchLenMax - 1) As Long
Nrnd As Long
Ncol As Long
End Type
Private Type KeyBlk ' Type to hold user key data
K(0 To KeyLenMax - 1) As Byte
End Type
Private Type IoBlk ' Type to hold cipher input and output blocks
IO(0 To BlkLenMax - 1) As Byte
End Type
Rem Change "d:/dll_pth" in the following lines to the directory path where the AES DLL is located
Private Declare Function AesBlkLen Lib "d:/dll_path/aes.dll" Alias "_aes_blk_len@8" (ByVal N As Long, C As AESctx) As Integer
Private Declare Function AesEncKey Lib "d:/dll_path/aes.dll" Alias "_aes_enc_key@12" (K As KeyBlk, ByVal N As Long, C As AESctx) As Integer
Private Declare Function AesDecKey Lib "d:/dll_path/aes.dll" Alias "_aes_dec_key@12" (K As KeyBlk, ByVal N As Long, C As AESctx) As Integer
Private Declare Function AesEncBlk Lib "d:/dll_path/aes.dll" Alias "_aes_enc_blk@12" (Ib As IoBlk, Ob As IoBlk, C As AESctx) As Integer
Private Declare Function AesDecBlk Lib "d:/dll_path/aes.dll" Alias "_aes_dec_blk@12" (Ib As IoBlk, Ob As IoBlk, C As AESctx) As Integer
Private Sub Hex(X As Byte) ' Output a byte in hexadecimal format
Dim H As Byte
H = Int(X / 16)
If H < 10 then
Debug.Print Chr(48 + H);
else
Debug.Print Chr(87 + H);
End If
H = Int(X Mod 16)
If H < 10 then
Debug.Print Chr(48 + H);
else
Debug.Print Chr(87 + H);
End If
End Sub
Private Sub OutKey(S As String, B As KeyBlk) ' Display a key value
Debug.Print: Debug.Print S;
For i = 0 To KeyLen - 1
Hex B.K(i)
Next i
End Sub
Private Sub OutBlock(S As String, B As IoBlk) ' Display an input/output block
Debug.Print: Debug.Print S;
For i = 0 To BlkLen - 1
Hex B.IO(i)
Next i
End Sub
Rem The following Main routine should output the following in the immediate window:
Rem Key = 00000000000000000000000000000000
Rem Input = 00000000000000000000000000000000
Rem Encrypted Text = 66e94bd4ef8a2c3b884cfa59ca342b2e
Rem Decrypted Text = 00000000000000000000000000000000
Sub Main()
Dim Key As KeyBlk ' These variables are automatically
Dim Ib As IoBlk, Ob As IoBlk, Rb As IoBlk
Dim Cx As AESctx ' initialised to zero values in VBA
Dim RetVal As Integer
BlkLen = 16: KeyLen = 16
Rem RetVal = AesBlkLen(BlkLen, Cx) ' include if the cipher block size is variable
OutKey "Key = ", Key
OutBlock "Input = ", Ib
RetVal = AesEncKey(Key, KeyLen, Cx) ' set an all zero encryption key
RetVal = AesEncBlk(Ib, Ob, Cx) ' encrypt Ib to Ob
OutBlock "Encrypted Text = ", Ob
RetVal = AesDecKey(Key, KeyLen, Cx) ' set an all zero decryption key
RetVal = AesDecBlk(Ob, Rb, Cx) ' decrypt Ob to Rb
OutBlock "Decrypted Text = ", Rb
Debug.Print
End Sub
 
请主要介绍一下
Private Type AESctx ' Type to hold the AES context data
Ekey(0 To KeySchLenMax - 1) As Long
Nrnd As Long
Ncol As Long
End Type
Private Type KeyBlk ' Type to hold user key data
K(0 To KeyLenMax - 1) As Byte
End Type
Private Type IoBlk ' Type to hold cipher input and output blocks
IO(0 To BlkLenMax - 1) As Byte
End Type

在Delphi中应该怎样定义数据类型。
Private Declare Function AesEncKey Lib "d:/dll_path/aes.dll" Alias "_aes_enc_key@12" (K As KeyBlk, ByVal N As Long, C As AESctx) As Integer

在Delphi中应该怎样声明函数
谢谢!
 
up.........
 
各位帮帮忙,请问这个DLL中的几个函数名是什么??
谢谢!
 
幫你整理了Delphi的宣告:
const
BlkLenMax = 32;
// maximum block length in bytes
KeyLenMax = 32;
// maximum block length in bytes
KeySchLenMax = 128;
// maximum key schedule length in bytes
type
TAESctx = packed record //Type to hold the AES context data
Ekey: array[0..KeySchLenMax - 1] of integer;
Nrnd: integer;
Ncol: integer;
end;

TKeyBlk = array[0..KeyLenMax - 1] of Byte;
// Type to hold user key data
TIoBlk = array[0..BlkLenMax - 1] of Byte;
//Type to hold cipher input and output blocks
function AesBlkLen(N: integer;
var C: TAESctx): smallint;
stdcall;
external 'aes.dll' name '_aes_blk_len@8';
function AesEncKey(const K: TKeyBlk;
N: integer;
const C: TAESctx): smallint;
stdcall;
external 'aes.dll' name '_aes_enc_key@12';
function AesDecKey(const K: TKeyBlk;
N: integer;
const C: TAESctx): smallint;
stdcall;
external 'aes.dll' name '_aes_dec_key@12';
function AesEncBlk(const Ib: TIoBlk;
var Ob: TIoBlk;
const C: TAESctx): smallint;
stdcall;
external 'aes.dll' name '_aes_enc_blk@12';
function AesDecBlk(const Ib: TIoBlk;
var Ob: TIoBlk;
const C: TAESctx): smallint;
stdcall;
external 'aes.dll' name '_aes_dec_blk@12';
 
lorderic,多谢!
我开始也这样做的但是不能运行一直出现:“无法定位程序输入点_aes_blk_len@8于动态链接库
aes.dll上。“
这个DLL是美国即将采用的用来代替DES加密算法的新标准的加密算法,我想用它来加密数据
但是不会用,可否告诉我你的Email,我把所有的资料发给你。

谢谢!!!
 
多人接受答案了。
 
顶部