Recently because the company mass mail program needs to register for a period of time has not activated the user to activate the mail, the message has registered password needs to be restored to the user but because the password encryption is used in C # TripleDES complete, on hand and no ready-made Delphi implementation. Time is urgent, now the translation is too late, so after the search data repeatedly implemented successfully implemented in Delphi in C # encapsulated DLL methods (Function) and process (Procedure) is to write down the implementation steps for the XDJM to share:
1, establish: DotNetFunc.cs encapsulation to use the function, Procedure.
2, generate the key file, for the assembly strong name signature
Sn-k key.snk
3, the use of strong name signature, compiled into class library
Csc/t:library DotNetFunc.cs
4. Build Type library
TlbExp dotnetfunc.dll/out:dotnetfunc.tlb
5. Register DLL
RegAsm DotNetFunc.dll
6. Move into GAC Global assembly cache
Gacutil-i DotNetFunc.dll
7, Delphi in the call test
Uses variants, Comobj, Olectnrs, Activex;
Procedure Tform1.button1click (Sender:tobject);
Var
Sharpobject:variant;
testvalue:string;
Begin
Try
Try
Sharpobject: = Createoleobject (' Csharpserver.sharpobject ');
TestValue: = Sharpobject.decrypttripledes (Edit1.text);
Edit2.text: =testvalue;
Except
On E:exception do
Begin
ShowMessage (E.message);
End
End
Finally
Sharpobject: = unassigned;
End
End
Procedure Tform1.button2click (Sender:tobject);
Var
Sharpobject:variant;
testvalue:string;
Begin
Try
Try
Sharpobject: = Createoleobject (' Csharpserver.sharpobject ');
TestValue: = Sharpobject.encrypttripledes (Edit2.text);
Edit1.text: =testvalue;
Except
On E:exception do
Begin
ShowMessage (E.message);
End
End
Finally
Sharpobject: = unassigned;
End
End
Initialization
CoInitialize (nil);
Finalization
CoUninitialize;
End.