summaryrefslogtreecommitdiff
path: root/packages/fcl-base
diff options
context:
space:
mode:
authormichael <michael@3ad0048d-3df7-0310-abae-a5850022a9f2>2009-07-25 16:43:56 +0000
committermichael <michael@3ad0048d-3df7-0310-abae-a5850022a9f2>2009-07-25 16:43:56 +0000
commitb2d777866ac0a1de88c343d411ce37d75bf6ce4e (patch)
treef3370b214f924fc9b382cd80d2d32da5f771b889 /packages/fcl-base
parentcbc866c6baf3a7446f5cd8ed824d37adae541b68 (diff)
downloadfpc-b2d777866ac0a1de88c343d411ce37d75bf6ce4e.tar.gz
* Easy-to-use Constructor that accepts a string instead of key structure
git-svn-id: http://svn.freepascal.org/svn/fpc/trunk@13443 3ad0048d-3df7-0310-abae-a5850022a9f2
Diffstat (limited to 'packages/fcl-base')
-rw-r--r--packages/fcl-base/src/blowfish.pp22
1 files changed, 21 insertions, 1 deletions
diff --git a/packages/fcl-base/src/blowfish.pp b/packages/fcl-base/src/blowfish.pp
index c0021b9ca3..e02c2c2945 100644
--- a/packages/fcl-base/src/blowfish.pp
+++ b/packages/fcl-base/src/blowfish.pp
@@ -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. \ No newline at end of file
+end.