哪个版本的LockBox3在Delphi2010下运行?

时间:2016-08-19 11:24:14

标签: delphi delphi-2010 lockbox-3

在寻找AES-128加密技术时,我想在Delphi2010上运行Lockbox3。

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

来自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?如果是,那怎么样?我做错了什么? THX!

编辑:还有另一个托管LockBox3的GitHub项目,即https://github.com/TurboPack/LockBox3 最近的来源是在Delphi2010下进行 NOT 编译。 (有关问题的简短列表,请参阅OP下的评论)

修改:这里有一些我尝试使用的代码(并且失败了) - 我在这里发布,因为我没有设法将其格式化为评论:

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;

1 个答案:

答案 0 :(得分:2)

我在http://lockbox.seanbdurkin.id.au/HomePage维护L​​ockBox 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=="
相关问题