1

我在 Delphi 2007.Net 工作,在那里我可以找到使用 Rijndael 算法的示例。

再见。

4

4 回答 4

7

前段时间我写了这段代码,应该可以正常工作。

uses
   System.Security.Cryptography, 
   System.Text;

type
  TDynamicArrayOfByte = array of Byte;

function Encrypt(StrtoEncrypt, PK: string): TDynamicArrayOfByte; // pk, must be of a string of 32 characters
var
   miRijndael:  Rijndael;
   encrypted:   TDynamicArrayOfByte;
   toEncrypt:   TDynamicArrayOfByte;
   bytPK:       TDynamicArrayOfByte;
   i: integer;
begin
   Result     := nil;
   miRijndael := System.Security.Cryptography.RijndaelManaged.Create;
   try
    toEncrypt :=  System.Text.Encoding.UTF8.GetBytes(StrtoEncrypt);
    bytPK     :=  System.Text.Encoding.UTF8.GetBytes(PK);    
    miRijndael.Key := bytPK;
    miRijndael.GenerateIV;
    encrypted := (miRijndael.CreateEncryptor()).TransformFinalBlock(toEncrypt, 0, Length(toEncrypt));
    setlength(result, Length(miRijndael.IV) + Length(encrypted));

      for i:=0 to Length(miRijndael.IV)-1 do
         result[i] := miRijndael.IV[i];

      for i:=0 to Length(encrypted)-1 do
         result[i + Length(miRijndael.IV)] := encrypted[i];

   finally
      miRijndael.Clear();
   end;
end;

function DesEncrypt(BufferEncrypted: TDynamicArrayOfByte; PK: string): string; //   pk, must be of a string of 32 characters
var
   miRijndael:  Rijndael;
   encrypted:   TDynamicArrayOfByte;
   tempArray:   TDynamicArrayOfByte;
   bytPK:       TDynamicArrayOfByte;
   i : integer;
begin
   Result     := '';
   miRijndael := System.Security.Cryptography.RijndaelManaged.Create;
   setlength(tempArray, Length(miRijndael.IV));
   setlength(encrypted, Length(BufferEncrypted) - Length(miRijndael.IV));
   try
    bytPK     :=  System.Text.Encoding.UTF8.GetBytes(PK);
    miRijndael.Key :=  bytPK;

      for i:=0 to Length(tempArray)-1 do
         tempArray[i] := BufferEncrypted[i];

      for i:=0 to Length(encrypted)-1 do
         encrypted[i] := BufferEncrypted[i + Length(tempArray)];

    miRijndael.IV := tempArray;
    Result :=  System.Text.Encoding.UTF8.GetString((miRijndael.CreateDecryptor()).TransformFinalBlock(encrypted, 0, Length(encrypted)));
   finally
     miRijndael.Clear();
   end;
end;

再见。

于 2009-09-02T20:49:21.603 回答
0

Turbo Power LockBox,它提供对 Blowfish、RSA、MD5、SHA-1、DES、triple-DES、Rijndael和消息数字签名的支持。

https://sourceforge.net/projects/tplockbox/

于 2009-09-02T20:49:58.013 回答
0

Delphi Cryptography Page DCP 加密组件包含 Rijndael 算法的实现。由 David Barton (davebarton@bigfoot.com) http://www.scramdisk.clara.net/撰写,DCP Crypto 组件非常全面,可免费导出,对称密钥加密组件。

于 2009-09-07T15:56:37.653 回答
0

在http://rcolonel.tripod.com/有一些 delphi 源代码。你也许可以在 Delphi.net 中使用它。但是,您最好找到一个 .net 模块并使用它。您应该能够在 delphi.net 中使用 ac# 或 vb.net 模块。

于 2009-09-02T21:06:07.467 回答