首页
社区
课程
招聘
提供一个封装MIME,XXE,UUE和MD5变换的DLL,附VB和DELPHI调用示例源码
发表于: 2006-9-5 08:39 5067

提供一个封装MIME,XXE,UUE和MD5变换的DLL,附VB和DELPHI调用示例源码

2006-9-5 08:39
5067
感到使用VB等语言的兄弟调用这些现成的算法比较麻烦,特写个DLL,给大家调用,呵呵。。。。。。。。。
MIME也就是BASE64,其它的就不多说了。。。。。。。。
下面的源码是VB.NET写的,把其中的源码拷贝到VB6中也可编译。
把DLL拷贝到所写的VB工程目录下,然后把下面的声明加进去,就可调用了。。。。。。

Public Class Form1
    Declare Function EncodeMIME Lib "CryptPrj.dll" (ByVal lpszSource As String, ByVal lpszDst As String) As Long
    Declare Function DecodeMIME Lib "CryptPrj.dll" (ByVal lpszSource As String, ByVal lpszDst As String) As Long
    Declare Function EncodeXXE Lib "CryptPrj.dll" (ByVal lpszSource As String, ByVal lpszDst As String) As Long
    Declare Function DecodeXXE Lib "CryptPrj.dll" (ByVal lpszSource As String, ByVal lpszDst As String) As Long
    Declare Function EncodeUUE Lib "CryptPrj.dll" (ByVal lpszSource As String, ByVal lpszDst As String) As Long
    Declare Function DecodeUUE Lib "CryptPrj.dll" (ByVal lpszSource As String, ByVal lpszDst As String) As Long
    Declare Function MD5 Lib "CryptPrj.dll" (ByVal lpszSource As String, ByVal lpszDst As String) As Long

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim str1 As String
        Dim str2 As String
        str1 = Space(255)
        str2 = TextBox1.Text
        Select Case ComboBox1.SelectedIndex
            Case 0
                EncodeMIME(str2, str1)
            Case 1
                EncodeXXE(str2, str1)
            Case 2
                EncodeUUE(str2, str1)
            Case 3
                MD5(str2, str1)
        End Select
        TextBox2.Text = str1
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim str1 As String
        Dim str2 As String

        str1 = Space(255)
        str2 = TextBox1.Text
        Select Case ComboBox1.SelectedIndex
            Case 0
                DecodeMIME(str2, str1)
            Case 1
                DecodeXXE(str2, str1)
            Case 2
                DecodeUUE(str2, str1)
            Case 3
                str1 = ""
                MsgBox("不支持MD5逆运算")
        End Select
        TextBox2.Text = str1
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ComboBox1.SelectedIndex = 0
    End Sub
End Class

附DELPHI调用示例

unit CryptTest;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Edit1: TEdit;
    Label2: TLabel;
    Edit2: TEdit;
    RadioGroup1: TRadioGroup;
    Button1: TButton;
    Button2: TButton;
    procedure RadioGroup1Click(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
function EncodeMIME(src:PChar;dst:PChar):HRESULT;stdcall;external 'CryptPrj.dll';
function DecodeMIME(src:PChar;dst:PChar):HRESULT;stdcall;external 'CryptPrj.dll';
function EncodeXXE(src:PChar;dst:PChar):HRESULT;stdcall;external 'CryptPrj.dll';
function DecodeXXE(src:PChar;dst:PChar):HRESULT;stdcall;external 'CryptPrj.dll';
function EncodeUUE(src:PChar;dst:PChar):HRESULT;stdcall;external 'CryptPrj.dll';
function DecodeUUE(src:PChar;dst:PChar):HRESULT;stdcall;external 'CryptPrj.dll';
function MD5(src:PChar;dst:PChar):HRESULT;stdcall;external 'CryptPrj.dll';

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  str:string;
begin
   SetLength(str,255);
   case RadioGroup1.ItemIndex of
     0: EncodeMIME(PChar(edit1.Text),PChar(str));
     1: EncodeXXE(PChar(edit1.Text),PChar(str));
     2: EncodeUUE(PChar(edit1.Text),PChar(str));
     3: MD5(PChar(edit1.Text),PChar(str));
   end;
   edit2.Text:=str;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  str:string;
begin
   SetLength(str,255);
   case RadioGroup1.ItemIndex of
     0: DecodeMIME(PChar(edit1.Text),PChar(str));
     1: DecodeXXE(PChar(edit1.Text),PChar(str));
     2: DecodeUUE(PChar(edit1.Text),PChar(str));
     3: begin
          str:='';
          ShowMessage('未实现MD5逆运算');
        end;
   end;
   edit2.Text:=str;
end;

procedure TForm1.Edit1Change(Sender: TObject);
begin
  Edit2.Text:='';
end;

procedure TForm1.RadioGroup1Click(Sender: TObject);
begin
  edit2.Text:='';
end;

end.

[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!

上传的附件:
收藏
免费 0
支持
分享
最新回复 (1)
雪    币: 222
活跃值: (10)
能力值: ( LV8,RANK:130 )
在线值:
发帖
回帖
粉丝
2
好东西,不过如果LZ不提供DLL源码的话,这张帖子可能会被移去工具版块
2006-9-5 11:33
0
游客
登录 | 注册 方可回帖
返回
//