* Easy-to-use Constructor that accepts a string instead of key structure

git-svn-id: trunk@13443 -
This commit is contained in:
michael 2009-07-25 16:43:56 +00:00
parent 05ff453182
commit ff2e7e670b

View File

@ -47,6 +47,8 @@ type
Type Type
EBlowFishError = Class(EStreamError); EBlowFishError = Class(EStreamError);
{ TBlowFishStream }
TBlowFishStream = Class(TOwnerStream) TBlowFishStream = Class(TOwnerStream)
Private Private
FBF : TBlowFish; FBF : TBlowFish;
@ -55,6 +57,7 @@ Type
FPos : Int64; FPos : Int64;
Public Public
Constructor Create(AKey : TBlowFishKey; AKeySize : Byte; Dest: TStream); Constructor Create(AKey : TBlowFishKey; AKeySize : Byte; Dest: TStream);
Constructor Create(Const KeyPhrase : String; Dest: TStream);
Destructor Destroy; override; Destructor Destroy; override;
Property BlowFish : TBlowFish Read FBF; Property BlowFish : TBlowFish Read FBF;
end; end;
@ -77,6 +80,7 @@ Implementation
ResourceString ResourceString
SNoSeekAllowed = 'Seek not allowed on encryption streams'; SNoSeekAllowed = 'Seek not allowed on encryption streams';
SErrEmptyPassPhraseNotAllowed = 'Empty passphrase is not allowed in constructor';
{ Blowfish lookup tables } { Blowfish lookup tables }
@ -544,6 +548,22 @@ begin
FPos:=0; FPos:=0;
end; 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; Destructor TBlowFishStream.Destroy;
begin begin
@ -681,4 +701,4 @@ begin
Raise EBlowFishError.Create(SNoSeekAllowed); Raise EBlowFishError.Create(SNoSeekAllowed);
end; end;
end. end.