* 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
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.