mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-17 07:19:37 +02:00
* Easy-to-use Constructor that accepts a string instead of key structure
git-svn-id: trunk@13443 -
This commit is contained in:
parent
05ff453182
commit
ff2e7e670b
@ -47,6 +47,8 @@ type
|
||||
Type
|
||||
EBlowFishError = Class(EStreamError);
|
||||
|
||||
{ TBlowFishStream }
|
||||
|
||||
TBlowFishStream = Class(TOwnerStream)
|
||||
Private
|
||||
FBF : TBlowFish;
|
||||
@ -55,6 +57,7 @@ Type
|
||||
FPos : Int64;
|
||||
Public
|
||||
Constructor Create(AKey : TBlowFishKey; AKeySize : Byte; Dest: TStream);
|
||||
Constructor Create(Const KeyPhrase : String; Dest: TStream);
|
||||
Destructor Destroy; override;
|
||||
Property BlowFish : TBlowFish Read FBF;
|
||||
end;
|
||||
@ -77,6 +80,7 @@ Implementation
|
||||
|
||||
ResourceString
|
||||
SNoSeekAllowed = 'Seek not allowed on encryption streams';
|
||||
SErrEmptyPassPhraseNotAllowed = 'Empty passphrase is not allowed in constructor';
|
||||
|
||||
{ Blowfish lookup tables }
|
||||
|
||||
@ -544,6 +548,22 @@ begin
|
||||
FPos:=0;
|
||||
end;
|
||||
|
||||
constructor TBlowFishStream.Create(const KeyPhrase: String; Dest: TStream);
|
||||
|
||||
Var
|
||||
KLen : Integer;
|
||||
K : TBlowFishKey;
|
||||
|
||||
begin
|
||||
If (KeyPhrase='') then
|
||||
Raise EBlowFishError.Create(SErrEmptyPassPhraseNotAllowed);
|
||||
KLen:=Length(KeyPhrase);
|
||||
If KLen>56 then
|
||||
KLen:=56;
|
||||
Move(KeyPhrase[1],K,Klen);
|
||||
Create(K,KLen,Dest);
|
||||
end;
|
||||
|
||||
Destructor TBlowFishStream.Destroy;
|
||||
|
||||
begin
|
||||
@ -681,4 +701,4 @@ begin
|
||||
Raise EBlowFishError.Create(SNoSeekAllowed);
|
||||
end;
|
||||
|
||||
end.
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user