在Delphi中使用SSL但仍然只有一个exe

时间:2009-11-19 09:29:17

标签: delphi dll exe indy

我们使用Indy,我们的应用程序需要SSL电子邮件支持,但是我们需要将我们的应用程序放在一个.Exe中。

我们知道默认的Indy处理程序需要在路径中包含dll。从EXE的一个资源中提取Dll将是最后的选择。

有更好的想法吗?

8 个答案:

答案 0 :(得分:8)

尝试SSLBlackBox

答案 1 :(得分:4)

托德里给了你一个很好的答案。我也使用SecureBlackBox。 您可以考虑其他一些第三方组件:

答案 2 :(得分:3)

请注意:如果您在可执行文件中添加SSL / TLS支持,它可能会变为restricted for export。如果您在美国,这可能意味着您的申请不能出售或提供给美国以外的人。这就是为什么这些DLL本身不是Indy或Delphi的一部分。

Delphi使用的库实际上是从OpenSSL项目编译的DLL。但是如果您对C有很好的了解,那么您应该能够将源代码编译为.obj文件,并将它们与您的Delphi代码链接起来。您可能还需要为此修改部分Indy代码。当然,其他人也可以做到这一点,但由于这些出口限制,这使得Indy组件(甚至Delphi本身)的出口更加复杂。

有趣的是,源代码受第一修正案的保护,它基本上允许您在一本书中打印代码,然后将其发送给一些流氓国家。如果你以数字形式(编译或不编译)发送它,那么你是在犯下联邦罪行,并且在洗澡时拿起肥皂至少一年时可能要小心......没有人声称法律是有道理的。他们可能只是[哔]的痛苦......

其他SSL解决方案无法与Indy组件一起使用,这意味着您必须重写部分代码以支持其他解决方案。


This link告诉您如何从内存加载DLL,因此您不需要在磁盘上加载它。这是我没有尝试过的替代解决方案。我不认为它会起作用,因为这两个DLL依赖于彼此,但它可能值得一试......

答案 3 :(得分:2)

出于分发目的是“单个EXE”要求,还是在客户端计算机上运行时它也必须是单个.EXE文件?

如果它仅用于分发目的,您可以将DLL文件附加到.EXE文件的末尾,然后 - 当程序启动时 - 从.EXE文件中提取它们并将它们本地存储为.DLL文件,类似于这样:

VAR F,O : FILE;
VAR BUF : ARRAY[1..<MaxSizeOfDLLs>] OF BYTE;
ASSIGN(F,ParamStr(0)); RESET(F,1);
SEEK(F,<OriginalExeSize>);
BLOCKREAD(F,BUF,<FirstDllSize>);
ASSIGN(O,<NameOfFirstDLL>); REWRITE(O,1);
BLOCKWRITE(O,BUF,<FirstDllSize>); CLOSE(O);
BLOCKREAD(F,BUF,<SecondDllSize>);
ASSIGN(O,<NameOfSecondDLL>); REWRITE(O,1);
BLOCKWRITE(O,BUF,<SecondDllSize>); CLOSE(O);
SEEK(F,<OriginalExeSize>); TRUNCATE(F); CLOSE(F)

Quick'n'Dirty,格式不正确等等,但应该给你基本的想法。

答案 4 :(得分:2)

您是否尝试过自己编译OpenSLL源并将目标文件导入Delphi?

推荐阅读:Using C object files in Delphi - 解释如何创建不需要DLL的程序,并且可以部署在一起

答案 5 :(得分:1)

我使用Microsoft的CAPICOM用于SSl3并且它解决了我的需求......它可以自由再分发已停止

如果您尝试其他组件,可能应该查看SYNAPSE(http://synapse.ararat.cz/)(我也使用)它可以与StreamSec(和其他人)一起使用ssl发送电子邮件。它免费且易于使用。

答案 6 :(得分:0)

Const

  cdoSendUsingMethod = 'http://schemas.microsoft.com/cdo/configuration/sendusing';  
  cdoSMTPServer = 'http://schemas.microsoft.com/cdo/configuration/smtpserver';  
  cdoSMTPServerPort = 'http://schemas.microsoft.com/cdo/configuration/smtpserverport';  
  cdoSendServerPort = '25';  
  cdoSendUsingPort = 2;  
  cdoSMTPConnectionTimeout = 'http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout';  
  cdoSMTPAuthenticate = 'http://schemas.microsoft.com/cdo/configuration/smtpauthenticate';  
  cdoAnonymous = '0';  
  cdoBasic = '1';  
  cdoSMTPUseSSL = 'http://schemas.microsoft.com/cdo/configuration/smtpusessl';  
  cdoSendUserName = 'http://schemas.microsoft.com/cdo/configuration/sendusername';  
  cdoSendPassword = 'http://schemas.microsoft.com/cdo/configuration/sendpassword';  
  cdoURLGetLatestVersion = 'http://schemas.microsoft.com/cdo/configuration/urlgetlatestversion';  

...

function SensCDOMail (ASubject, AFrom, ATo, ABody, ASmtpServer : WideString): String;  
var 

  cdoMessage:OleVariant;  
  cdoConfiguration: OleVariant;  

begin  

  //Configuration Object  
  cdoMessage:= CreateOleObject('CDO.Message');  
  cdoConfiguration:= CreateOleObject('CDO.Configuration');  
  try  

    cdoConfiguration.Fields(cdoSendUsingMethod):= cdoSendUsingPort;  
    cdoConfiguration.Fields(cdoSMTPServer):= ASmtpServer;  
    cdoConfiguration.Fields(cdoSMTPServerPort):= cdoSendServerPort;  
    cdoConfiguration.Fields(cdoSMTPAuthenticate):= cdoAnonymous;  
    cdoConfiguration.Fields(cdoSMTPUseSSL ):= True; // use SSL  
    cdoConfiguration.Fields.Update;  
    cdoMessage.Configuration:= cdoConfiguration;  
    cdoMessage.To       := ATo;
    cdoMessage.From     := AFrom;
    cdoMessage.Subject  := ASubject;
    //cdoMessage.HTMLBody := ABody;   //Want to send in Html format
    cdoMessage.TextBody := ABody;     //Want to send in text format
    cdoMessage.Send;

  finally  
    VarClear(cdoMessage);  
    VarClear(cdoConfiguration);  
  end;  
end;  

cdoSendUsingMethod = 'http://schemas.microsoft.com/cdo/configuration/sendusing'; cdoSMTPServer = 'http://schemas.microsoft.com/cdo/configuration/smtpserver'; cdoSMTPServerPort = 'http://schemas.microsoft.com/cdo/configuration/smtpserverport'; cdoSendServerPort = '25'; cdoSendUsingPort = 2; cdoSMTPConnectionTimeout = 'http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout'; cdoSMTPAuthenticate = 'http://schemas.microsoft.com/cdo/configuration/smtpauthenticate'; cdoAnonymous = '0'; cdoBasic = '1'; cdoSMTPUseSSL = 'http://schemas.microsoft.com/cdo/configuration/smtpusessl'; cdoSendUserName = 'http://schemas.microsoft.com/cdo/configuration/sendusername'; cdoSendPassword = 'http://schemas.microsoft.com/cdo/configuration/sendpassword'; cdoURLGetLatestVersion = 'http://schemas.microsoft.com/cdo/configuration/urlgetlatestversion';

答案 7 :(得分:0)

可以将这些DLL作为资源包含在程序的可执行文件中,并在使用时将它们导出到文件中,甚至可以使用它们而不首先通过重新定位代码并搜索内存中的入口点来导出它们。我有代码在某处做后者......