【问题标题】:Which version of LockBox3 works under Delphi2010?Delphi2010下哪个版本的LockBox3工作?
【发布时间】:2016-09-07 09:21:18
【问题描述】:

由于我正在寻找 AES-128 加密,我想让 Lockbox3 在 Delphi2010 上运行。

这里的第一个问题:官方来源是什么/在哪里?

https://sourceforge.net/projects/tplockbox/ 的源代码不包含 Delphi2010 的包,也根本不编译(大量错误)。

https://code.google.com/archive/p/tplockbox/ 不再维护,指向https://github.com/SeanBDurkin/tplockbox

我从 github 下载了源代码,我想是在 V3.6.3 中(源代码中没有提到版本,对吧?)。可以安装软件包,但例如MakeSampleKey 示例无法编译,因为 EncryptString 不适用于 AnsiStrings(umfmMakeSampleKey.pas,第 216 行)。

然后我创建了一个项目并使用了来自How to AES-128 encrypt a string using a password in Delphi and decrypt in C#?的OP的源代码

我将 CipherText 从 AnsiString 更改为 String。代码可以编译,但是当我运行它时,它会在 TPLB3.SHA1.pas 第 264 行出现“整数溢出”而崩溃。

LockBox3 是否仍在维护,是否可用于 Delphi2010?如果是,那么如何?我做错了什么?谢谢!

编辑: 还有另一个托管 LockBox3 的 GitHub 项目,即https://github.com/TurboPack/LockBox3 从那里最近的来源确实在Delphi2010下编译。 (有关问题的简短列表,请参阅 OP 下的 cmets)

编辑:这是我尝试使用(但失败)的一些代码 - 我将其发布在这里,因为我无法将其格式化为评论:

function LockBox3_EncryptText_AES_128(input: string; password: string): string;
var
  Codec: TCodec;
  CipherText: String;
begin
  Codec := TCodec.Create(nil);
  try
    Codec.CryptoLibrary := TCryptographicLibrary.Create(Codec);
    Codec.StreamCipherId := BlockCipher_ProgID;
    Codec.BlockCipherId := Format(AES_ProgId, [128]);
    Codec.ChainModeId := CBC_ProgId;
    Codec.Password := Password;
    Codec.EncryptString(input, CipherText);
    Result := string(CipherText);
  finally
    Codec.Free;
  end;
end;

【问题讨论】:

  • Github 的源代码在所有受支持的 Delphi 版本下构建,并且由于它是代码的当前存储库(如您所见,因为它是大约一个月前最后一次更新),您应该看看那里.每个版本的 IDE 不再有单独的包,而且已经很久没有了。 Github 上的版本在西雅图和柏林运行良好,这意味着它适用于 Unicode 字符串。
  • 刚刚检查了 Github,安装说明就在 github.com/TurboPack/LockBox3 页面上 - 在该页面上向下滚动以阅读 readme.txt 的内容。
  • Ken,您指向的是不同的 Github 存储库。 (/TurboPack/LockBox3 vs. /SeanBDurkin/tplockbox)我在发布原始请求之前尝试了该存储库,现在我再次测试。我检查了来自github.com/TurboPack/LockBox3.git/trunk 的源代码,我添加了所需的搜索路径,并尝试编译 LockBox3VCLDD.dpk。它失败并显示“[MSBuild Fehler] 0 ist ein ungültiger Wert für den DebugInformation-Parameter der DCC-Aufgabe。Der DebugInformation-Parameter gehört zum System.Boolean-Typ。”再次:我正在使用 Delphi2010。你试过什么版本的 Delphi?
  • 顺便说一句:当我删除所有可能阻止程序包编译的二进制内容时,它会在单元 uTPLb_StrUtils.pas 中以“未知标识符“TEncoding.ANSI”停止
  • 是的,我知道我指向的是不同的存储库。我已经在 D2007、XE、XE8、10 Seattle 和 10.1 Berlin 中安装了那个版本。如果它适用于所有这些(ANSI 和 Unicode),我认为它没有理由不适用于 2010。(我的德语不流利,但您引用的错误消息似乎说明了一些关于一个无效的参数,它需要一个布尔值。如果可以的话,提供错误的翻译通常很有帮助(因为这是一个英语网站)。)

标签: delphi delphi-2010 lockbox-3


【解决方案1】:

我在 http://lockbox.seanbdurkin.id.au/HomePage 维护 LockBox 3。

回购地址为https://github.com/SeanBDurkin/tplockbox

是的,它适用于 D2010。


更新

这适用于我,使用 Delphi 2010 和 TPLB3 版本 3.6.3

program LB3Demo_D2010;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  TPLB3.Codec in '..\ExternalLibraries\TPLB3\run\TPLB3.Codec.pas',
  TPLB3.CryptographicLibrary in '..\ExternalLibraries\TPLB3\run\TPLB3.CryptographicLibrary.pas',
  TPLB3.BlockCipher in '..\ExternalLibraries\TPLB3\run\TPLB3.BlockCipher.pas',
  TPLB3.StreamToBlock in '..\ExternalLibraries\TPLB3\run\TPLB3.StreamToBlock.pas',
  TPLB3.Decorators in '..\ExternalLibraries\TPLB3\run\TPLB3.Decorators.pas',
  TPLB3.StreamCipher in '..\ExternalLibraries\TPLB3\run\TPLB3.StreamCipher.pas',
  TPLB3.StreamUtils in '..\ExternalLibraries\TPLB3\run\TPLB3.StreamUtils.pas',
  TPLB3.Random in '..\ExternalLibraries\TPLB3\run\TPLB3.Random.pas',
  TPLB3.IntegerUtils in '..\ExternalLibraries\TPLB3\run\TPLB3.IntegerUtils.pas',
  TPLB3.Compatibility in '..\ExternalLibraries\TPLB3\run\TPLB3.Compatibility.pas',
  TPLB3.Asymetric in '..\ExternalLibraries\TPLB3\run\TPLB3.Asymetric.pas',
  TPLB3.CodecIntf in '..\ExternalLibraries\TPLB3\run\TPLB3.CodecIntf.pas',
  TPLB3.BaseNonVisualComponent in '..\ExternalLibraries\TPLB3\run\TPLB3.BaseNonVisualComponent.pas',
  TPLB3.Hash in '..\ExternalLibraries\TPLB3\run\TPLB3.Hash.pas',
  TPLB3.HashDsc in '..\ExternalLibraries\TPLB3\run\TPLB3.HashDsc.pas',
  TPLB3.AES in '..\ExternalLibraries\TPLB3\run\TPLB3.AES.pas',
  TPLB3.Base64 in '..\ExternalLibraries\TPLB3\run\TPLB3.Base64.pas',
  TPLB3.CBC in '..\ExternalLibraries\TPLB3\run\TPLB3.CBC.pas',
  TPLB3.Constants in '..\ExternalLibraries\TPLB3\run\TPLB3.Constants.pas',
  TPLB3.ECB in '..\ExternalLibraries\TPLB3\run\TPLB3.ECB.pas',
  TPLB3.MD5 in '..\ExternalLibraries\TPLB3\run\TPLB3.MD5.pas',
  TPLB3.SimpleBlockCipher in '..\ExternalLibraries\TPLB3\run\TPLB3.SimpleBlockCipher.pas',
  TPLB3.I18n in '..\ExternalLibraries\TPLB3\run\TPLB3.I18n.pas',
  TPLB3.CFB_8Bit in '..\ExternalLibraries\TPLB3\run\TPLB3.CFB_8Bit.pas',
  TPLB3.CFB_Block in '..\ExternalLibraries\TPLB3\run\TPLB3.CFB_Block.pas',
  TPLB3.CTR in '..\ExternalLibraries\TPLB3\run\TPLB3.CTR.pas',
  TPLB3.OFB in '..\ExternalLibraries\TPLB3\run\TPLB3.OFB.pas',
  TPLB3.PCBC in '..\ExternalLibraries\TPLB3\run\TPLB3.PCBC.pas',
  TPLB3.SHA1 in '..\ExternalLibraries\TPLB3\run\TPLB3.SHA1.pas',
  TPLB3.SHA2 in '..\ExternalLibraries\TPLB3\run\TPLB3.SHA2.pas',
  TPLB3.SVN_Keywords in '..\ExternalLibraries\TPLB3\run\TPLB3.SVN_Keywords.pas',
  TPLB3.BinaryUtils in '..\ExternalLibraries\TPLB3\run\TPLB3.BinaryUtils.pas',
  TPLB3.PointerArithmetic in '..\ExternalLibraries\TPLB3\run\TPLB3.PointerArithmetic.pas',
  TPLB3.CipherUtils in '..\ExternalLibraries\TPLB3\run\TPLB3.CipherUtils.pas',
  TPLB3.RSA_Engine in '..\ExternalLibraries\TPLB3\run\TPLB3.RSA_Engine.pas',
  TPLB3.RSA_Primitives in '..\ExternalLibraries\TPLB3\run\TPLB3.RSA_Primitives.pas',
  TPLB3.HugeCardinal in '..\ExternalLibraries\TPLB3\run\TPLB3.HugeCardinal.pas',
  TPLB3.HugeCardinalUtils in '..\ExternalLibraries\TPLB3\run\TPLB3.HugeCardinalUtils.pas',
  TPLB3.MemoryStreamPool in '..\ExternalLibraries\TPLB3\run\TPLB3.MemoryStreamPool.pas',
  TPLB3.DES in '..\ExternalLibraries\TPLB3\run\TPLB3.DES.pas',
  TPLB3.BlowFish in '..\ExternalLibraries\TPLB3\run\TPLB3.BlowFish.pas',
  TPLB3.TDES in '..\ExternalLibraries\TPLB3\run\TPLB3.TDES.pas',
  TPLB3.TwoFish in '..\ExternalLibraries\TPLB3\run\TPLB3.TwoFish.pas',
  TPLB3.XXTEA in '..\ExternalLibraries\TPLB3\run\TPLB3.XXTEA.pas',
  TPLB3.DCP.twofish_Modified in '..\ExternalLibraries\TPLB3\run\TPLB3.DCP.twofish_Modified.pas';

const
  /// <remarks>Set isProduction to True for a production environment.
  ///  For a production environment, we want to randomize the PRNG at start-up,
  ///  for security reasons. For a test environment, we may way to set the seed
  ///  to be a fixed known value, for purposes of reproducibility and possibly
  ///  KAT alignment.
  /// </remarks>
  isProduction: boolean = False;
  Seed_ForNonProduction: int64 = 1;

function LockBox3_EncryptText_AES_128( input: string; password: string): string;
var
  Codec: TCodec;
begin
  Codec := TCodec.Create( nil);
  try
    Codec.CryptoLibrary  := TCryptographicLibrary.Create(Codec);
    Codec.StreamCipherId := BlockCipher_ProgID;
    Codec.BlockCipherId  := Format(AES_ProgId, [128]);
    Codec.ChainModeId    := CBC_ProgId;
    Codec.Password       := Password;
    Codec.EncryptString( input, result);
    Codec.Burn
  finally
    Codec.Free
  end
end;

var
  input, output: string;
  password: string;
begin
  try
    if isProduction then
        TRandomStream.Instance.Randomize
      else
        TRandomStream.Instance.Seed := Seed_ForNonProduction;
    input    := 'Hello world';
    WriteLn( 'Compiler = ', Format( '%.1f', [CompilerVersion]));
    WriteLn( 'Plaintext = "' + input + '"');
    password := 'my-secret';
    WriteLn( 'Password (' + {$IFDEF UNICODE} 'UTF-16' {$ELSE} 'UTF-8' {$ENDIF} + ') = "' + password + '"');
    WriteLn( 'Seed = ', TRandomStream.Instance.Seed);
    output   := LockBox3_EncryptText_AES_128( input, password);
    Writeln( 'Ciphertext (encoded as base64) = "' + output + '"');
    WriteLn( 'Press enter to terminate.');
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

输出

运行时,输出产生 ...

Compiler = 21.0
Plaintext = "Hello world"
Password (UTF-16) = "my-secret"
Seed = 1
Ciphertext (encoded as base64) = "AQAAAAAAAADCpkdd/g8fyEuojQ=="

【讨论】:

  • 感谢您的帮助。我知道那个存储库并且我已经安装了它。但是,我无法让它工作。我尝试使用来自delphipraxis.net/185039-lockbox-3-string-verschluesseln.html 的代码加密一些文本,但在 Codec.Password:=... 行中,我在 TSHA1_Hasher.Update(文件 TPLB3.SHA1.pas)中得到一个 EIntOverflow 异常。正如您论坛中所建议的那样,我在本单元中禁用了溢出检查。代码现在在 Stream_to_Base64 中的 Codec.EncryptString 上发生 ERangeError 崩溃(单元 TPLB3.StreamUtils.pas 第 310 行)关闭范围检查真的是个好主意吗?
  • 请发布一些不起作用的示例代码。您的评论中没有足够的信息来处理。
  • 我已经在原帖中添加了代码。代码来自我之前评论中的 delphipraxis-link。只需使用“someText”和“somePassword”调用该方法就会产生崩溃。
  • 谢谢,现在可以了。必须对源进行一些采用(SHA1.pas 和 StreamUtils.pas 中的 {$R-}{$Q-})以避免范围检查和溢出错误,然后它似乎可以工作
  • 更新:我现在发布了 LockBox 3.7.0 。它具有所有这些修复程序,支持客户端提供的 IV,并具有 D10.1 Berlin 和 XE8 的项目负责人。转至github.com/SeanBDurkin/tplockbox
猜你喜欢
  • 2011-04-15
  • 1970-01-01
  • 2014-08-25
  • 2015-12-31
  • 2013-03-02
  • 1970-01-01
  • 1970-01-01
  • 2016-03-08
  • 2016-11-03
相关资源
最近更新 更多