⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lbclass.pas

📁 tool pour ubuntu 8.10
💻 PAS
📖 第 1 页 / 共 3 页
字号:
  OutS := TMemoryStream.Create;
  try
    InS.SetSize(InBufSize);
    InS.Write(InBuf, InBufSize);
    InS.Position := 0;
    DecryptStream(InS, OutS);
    OutS.Position := 0;
    OutS.Read(OutBuf, OutS.Size);
    Result := OutS.Size;
  finally
    InS.Free;
    OutS.Free;
  end;
end;
{ -------------------------------------------------------------------------- }
function TLbCipher.EncryptBuffer(const InBuf; InBufSize : Cardinal; var OutBuf) : Cardinal;
var
  InS, OutS : TMemoryStream;
begin
  InS := TMemoryStream.Create;
  OutS := TMemoryStream.Create;
  try
    InS.SetSize(InBufSize);
    InS.Write(InBuf, InBufSize);
    InS.Position := 0;
    EncryptStream(InS, OutS);
    OutS.Position := 0;
    OutS.Read(OutBuf, OutS.Size);
    Result := OutS.Size;
  finally
    InS.Free;
    OutS.Free;
  end;
end;


{ == TLbSymmetricCipher ==================================================== }
constructor TLbSymmetricCipher.Create(AOwner : TComponent);
begin
  inherited Create(AOwner);
end;
{ -------------------------------------------------------------------------- }
destructor TLbSymmetricCipher.Destroy;
begin
  inherited Destroy;
end;


{ == TLbBlowfish =========================================================== }
constructor TLbBlowfish.Create(AOwner : TComponent);
begin
  inherited Create(AOwner);
end;
{ -------------------------------------------------------------------------- }
destructor TLbBlowfish.Destroy;
begin
  inherited Destroy;
end;
{ -------------------------------------------------------------------------- }
procedure TLbBlowfish.DecryptFile(const InFile, OutFile : string);
begin
  case CipherMode of
    cmECB : BFEncryptFile(InFile, OutFile, FKey, False);
    cmCBC : BFEncryptFileCBC(InFile, OutFile, FKey, False);
  end;
end;
{ -------------------------------------------------------------------------- }
procedure TLbBlowfish.DecryptStream(InStream , OutStream : TStream);
begin
  case CipherMode of
    cmECB : BFEncryptStream(InStream, OutStream, FKey, False);
    cmCBC : BFEncryptStreamCBC(InStream, OutStream, FKey, False);
  end;
end;
{ -------------------------------------------------------------------------- }
function TLbBlowfish.DecryptString(const InString : string) : string;
begin
  case CipherMode of
    cmECB : Result := BFEncryptStringEx(InString, FKey, False);
    cmCBC : Result := BFEncryptStringCBCEx(InString, FKey, False);
  end;
end;
{ -------------------------------------------------------------------------- }
procedure TLbBlowfish.EncryptFile(const InFile, OutFile : string);
begin
  case CipherMode of
    cmECB : BFEncryptFile(InFile, OutFile, FKey, True);
    cmCBC : BFEncryptFileCBC(InFile, OutFile, FKey, True);
  end;
end;
{ -------------------------------------------------------------------------- }
procedure TLbBlowfish.EncryptStream(InStream, OutStream : TStream);
begin
  case CipherMode of
    cmECB : BFEncryptStream(InStream, OutStream, FKey, True);
    cmCBC : BFEncryptStreamCBC(InStream, OutStream, FKey, True);
  end;
end;
{ -------------------------------------------------------------------------- }
function TLbBlowfish.EncryptString(const InString : string) : string;
begin
  case CipherMode of
    cmECB : Result := BFEncryptStringEx(InString, FKey, True);
    cmCBC : Result := BFEncryptStringCBCEx(InString, FKey, True);
  end;
end;
{ -------------------------------------------------------------------------- }
procedure TLbBlowfish.GenerateKey(const Passphrase : string);
begin
  GenerateLMDKey(FKey, SizeOf(FKey), Passphrase);
end;
{ -------------------------------------------------------------------------- }
procedure TLbBlowfish.GenerateRandomKey;
begin
  LbCipher.GenerateRandomKey(FKey, SizeOf(FKey));
end;
{ -------------------------------------------------------------------------- }
procedure TLbBlowfish.GetKey(var Key : TKey128);
begin
  Key := FKey;
end;
{ -------------------------------------------------------------------------- }
procedure TLbBlowfish.SetKey(const Key : TKey128);
begin
  FKey := Key;
end;
{ -------------------------------------------------------------------------- }
function TLbBlowfish.OutBufSizeNeeded(InBufSize : Cardinal) : Cardinal;
var
  BlkCount, BlkSize : Cardinal;
begin
  BlkSize := SizeOf(TBFBlock);
  BlkCount := (InBufSize div BlkSize) + 1;                           {!!.05}
  Result := BlkCount * BlkSize;
end;


{ == TLbDES ================================================================ }
constructor TLbDES.Create(AOwner : TComponent);
begin
  inherited Create(AOwner);
end;
{ -------------------------------------------------------------------------- }
destructor TLbDES.Destroy;
begin
  inherited Destroy;
end;
{ -------------------------------------------------------------------------- }
procedure TLbDES.DecryptFile(const InFile, OutFile : string);
begin
  case CipherMode of
    cmECB : DESEncryptFile(InFile, OutFile, FKey, False);
    cmCBC : DESEncryptFileCBC(InFile, OutFile, FKey, False);
  end;
end;
{ -------------------------------------------------------------------------- }
procedure TLbDES.DecryptStream(InStream , OutStream : TStream);
begin
  case CipherMode of
    cmECB : DESEncryptStream(InStream, OutStream, FKey, False);
    cmCBC : DESEncryptStreamCBC(InStream, OutStream, FKey, False);
  end;
end;
{ -------------------------------------------------------------------------- }
function TLbDES.DecryptString(const InString : string) : string;
begin
  case CipherMode of
    cmECB : Result := DESEncryptStringEx(InString, FKey, False);
    cmCBC : Result := DESEncryptStringCBCEx(InString, FKey, False);
  end;
end;
{ -------------------------------------------------------------------------- }
procedure TLbDES.EncryptFile(const InFile, OutFile : string);
begin
  case CipherMode of
    cmECB : DESEncryptFile(InFile, OutFile, FKey, True);
    cmCBC : DESEncryptFileCBC(InFile, OutFile, FKey, True);
  end;
end;
{ -------------------------------------------------------------------------- }
procedure TLbDES.EncryptStream(InStream, OutStream : TStream);
begin
  case CipherMode of
    cmECB : DESEncryptStream(InStream, OutStream, FKey, True);
    cmCBC : DESEncryptStreamCBC(InStream, OutStream, FKey, True);
  end;
end;
{ -------------------------------------------------------------------------- }
function TLbDES.EncryptString(const InString : string) : string;
begin
  case CipherMode of
    cmECB : Result := DESEncryptStringEx(InString, FKey, True);
    cmCBC : Result := DESEncryptStringCBCEx(InString, FKey, True);
  end;
end;
{ -------------------------------------------------------------------------- }
procedure TLbDES.GenerateKey(const Passphrase : string);
begin
  GenerateLMDKey(FKey, SizeOf(FKey), Passphrase);
end;
{ -------------------------------------------------------------------------- }
procedure TLbDES.GenerateRandomKey;
begin
  LbCipher.GenerateRandomKey(FKey, SizeOf(FKey));
end;
{ -------------------------------------------------------------------------- }
procedure TLbDES.SetKey(const Key : TKey64);
begin
  FKey := Key;
end;
{ -------------------------------------------------------------------------- }
procedure TLbDES.GetKey(var Key : TKey64);
begin
  Key := FKey;
end;
{ -------------------------------------------------------------------------- }
function TLbDES.OutBufSizeNeeded(InBufSize : Cardinal) : Cardinal;
var
  BlkCount, BlkSize : Cardinal;
begin
  BlkSize := SizeOf(TDESBlock);
  BlkCount := (InBufSize div BlkSize) + 1;                           {!!.05}
  Result := BlkCount * BlkSize;
end;


{ == TLb3DES ================================================================ }
constructor TLb3DES.Create(AOwner : TComponent);
begin
  inherited Create(AOwner);
end;
{ -------------------------------------------------------------------------- }
destructor TLb3DES.Destroy;
begin
  inherited Destroy;
end;
{ -------------------------------------------------------------------------- }
procedure TLb3DES.DecryptFile(const InFile, OutFile : string);
begin
  case CipherMode of
    cmECB : TripleDESEncryptFile(InFile, OutFile, FKey, False);
    cmCBC : TripleDESEncryptFileCBC(InFile, OutFile, FKey, False);
  end;
end;
{ -------------------------------------------------------------------------- }
procedure TLb3DES.DecryptStream(InStream , OutStream : TStream);
begin
  case CipherMode of
    cmECB : TripleDESEncryptStream(InStream, OutStream, FKey, False);
    cmCBC : TripleDESEncryptStreamCBC(InStream, OutStream, FKey, False);
  end;
end;
{ -------------------------------------------------------------------------- }
function TLb3DES.DecryptString(const InString : string) : string;
begin
  case CipherMode of
    cmECB : Result := TripleDESEncryptStringEx(InString, FKey, False);
    cmCBC : Result := TripleDESEncryptStringCBCEx(InString, FKey, False);
  end;
end;
{ -------------------------------------------------------------------------- }
procedure TLb3DES.EncryptFile(const InFile, OutFile : string);
begin
  case CipherMode of
    cmECB : TripleDESEncryptFile(InFile, OutFile, FKey, True);
    cmCBC : TripleDESEncryptFileCBC(InFile, OutFile, FKey, True);
  end;
end;
{ -------------------------------------------------------------------------- }
procedure TLb3DES.EncryptStream(InStream, OutStream : TStream);
begin
  case CipherMode of
    cmECB : TripleDESEncryptStream(InStream, OutStream, FKey, True);
    cmCBC : TripleDESEncryptStreamCBC(InStream, OutStream, FKey, True);
  end;
end;
{ -------------------------------------------------------------------------- }
function TLb3DES.EncryptString(const InString : string) : string;
begin
  case CipherMode of
    cmECB : Result := TripleDESEncryptStringEx(InString, FKey, True);
    cmCBC : Result := TripleDESEncryptStringCBCEx(InString, FKey, True);
  end;
end;
{ -------------------------------------------------------------------------- }
procedure TLb3DES.GenerateKey(const Passphrase : string);
begin
  GenerateLMDKey(FKey, SizeOf(FKey), Passphrase);
end;
{ -------------------------------------------------------------------------- }
procedure TLb3DES.GenerateRandomKey;
begin
  LbCipher.GenerateRandomKey(FKey, SizeOf(FKey));
end;
{ -------------------------------------------------------------------------- }
procedure TLb3DES.SetKey(const Key : TKey128);
begin
  FKey := Key;
end;
{ -------------------------------------------------------------------------- }
procedure TLb3DES.GetKey(var Key : TKey128);
begin
  Key := FKey;
end;
{ -------------------------------------------------------------------------- }
function TLb3DES.OutBufSizeNeeded(InBufSize : Cardinal) : Cardinal;
var
  BlkCount, BlkSize : Cardinal;
begin
  BlkSize := SizeOf(TDESBlock);
  BlkCount := (InBufSize div BlkSize) + 1;                           {!!.05}
  Result := BlkCount * BlkSize;
end;


{ == TLbRijndael =========================================================== }
constructor TLbRijndael.Create(AOwner : TComponent);
begin
  inherited Create(AOwner);
end;
{ -------------------------------------------------------------------------- }
destructor TLbRijndael.Destroy;
begin
  inherited Destroy;
  KeySize := ks128;                                                    {!!.04}
end;
{ -------------------------------------------------------------------------- }
procedure TLbRijndael.DecryptFile(const InFile, OutFile : string);
begin
  case CipherMode of
    cmECB : RDLEncryptFile(InFile, OutFile, FKey, FKeySizeBytes, False);
    cmCBC : RDLEncryptFileCBC(InFile, OutFile, FKey, FKeySizeBytes, False);
  end;
end;
{ -------------------------------------------------------------------------- }
procedure TLbRijndael.DecryptStream(InStream , OutStream : TStream);
begin
  case CipherMode of
    cmECB : RDLEncryptStream(InStream, OutStream, FKey, FKeySizeBytes, False);
    cmCBC : RDLEncryptStreamCBC(InStream, OutStream, FKey, FKeySizeBytes, False);
  end;
end;
{ -------------------------------------------------------------------------- }
function TLbRijndael.DecryptString(const InString : string) : string;
begin
  case CipherMode of
    cmECB : Result := RDLEncryptStringEx(InString, FKey, FKeySizeBytes, False);
    cmCBC : Result := RDLEncryptStringCBCEx(InString, FKey, FKeySizeBytes, False);
  end;
end;
{ -------------------------------------------------------------------------- }
procedure TLbRijndael.EncryptFile(const InFile, OutFile : string);
begin
  case CipherMode of
    cmECB : RDLEncryptFile(InFile, OutFile, FKey, FKeySizeBytes, True);
    cmCBC : RDLEncryptFileCBC(InFile, OutFile, FKey, FKeySizeBytes, True);
  end;
end;
{ -------------------------------------------------------------------------- }
procedure TLbRijndael.EncryptStream(InStream, OutStream : TStream);
begin
  case CipherMode of
    cmECB : RDLEncryptStream(InStream, OutStream, FKey, FKeySizeBytes, True);
    cmCBC : RDLEncryptStreamCBC(InStream, OutStream, FKey, FKeySizeBytes, True);
  end;
end;
{ -------------------------------------------------------------------------- }
function TLbRijndael.EncryptString(const InString : string) : string;
begin
  case CipherMode of
    cmECB : Result := RDLEncryptStringEx(InString, FKey, FKeySizeBytes, True);
    cmCBC : Result := RDLEncryptStringCBCEx(InString, FKey, FKeySizeBytes, True);
  end;
end;
{ -------------------------------------------------------------------------- }
procedure TLbRijndael.GenerateKey(const Passphrase : string);
begin
  GenerateLMDKey(FKey, FKeySizeBytes, Passphrase);
end;
{ -------------------------------------------------------------------------- }
procedure TLbRijndael.GenerateRandomKey;
begin
  LbCipher.GenerateRandomKey(FKey, FKeySizeBytes);
end;
{ -------------------------------------------------------------------------- }
procedure TLbRijndael.GetKey(var Key);
begin
  Move(FKey, Key, FKeySizeBytes);
end;
{ -------------------------------------------------------------------------- }
procedure TLbRijndael.SetKey(const Key);
begin
  Move(Key, FKey, FKeySizeBytes);
end;
{ -------------------------------------------------------------------------- }
procedure TLbRijndael.SetKeySize(Value : TLbKeySizeRDL);
begin
  FKeySize := Value;
  FKeySizeBytes := RDLKeySizeMap[Value];
end;
{ -------------------------------------------------------------------------- }
function TLbRijndael.OutBufSizeNeeded(InBufSize : Cardinal) : Cardinal;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -