@@ -640,6 +640,11 @@ TDECPasswordHash = class(TDECHashAuthentication)
640640 // / </summary>
641641 FSalt : TBytes;
642642
643+ // / <summary>
644+ // / Overwrite the salt value
645+ // / </summary>
646+ procedure DoDone ; override;
647+
643648 { $Region CryptFormatHandling}
644649 // / <summary>
645650 // / Returns the ID code for Crypt/BSD like storing of passwords. The ID
@@ -650,7 +655,7 @@ TDECPasswordHash = class(TDECHashAuthentication)
650655 // / If the algorithm on which this is being used is a Crypt/BSD compatible
651656 // / password hash algorithm the ID is returned otherwise an empty string.
652657 // / </returns>
653- class function GetCryptID :RawByteString ; virtual ;
658+ class function GetCryptID :string ; virtual ;
654659
655660 // / <summary>
656661 // / Returns the parameters required for the crypt-like password storing
@@ -667,8 +672,8 @@ TDECPasswordHash = class(TDECHashAuthentication)
667672 // / Returns an empty string if the the algorithm on which this is being
668673 // / used is not a Crypt/BSD compatible password hash algorithm
669674 // / </returns>
670- class function GetCryptParams (const Params : RawByteString ;
671- Format : TDECFormatClass):RawByteString ; virtual ;
675+ class function GetCryptParams (const Params : string ;
676+ Format : TDECFormatClass):string ; virtual ;
672677 // / <summary>
673678 // / Returns the salt required for the crypt-like password storing
674679 // / in that format.
@@ -679,8 +684,8 @@ TDECPasswordHash = class(TDECHashAuthentication)
679684 // / <param name="Format">
680685 // / Format class for formatting the output
681686 // / </param>
682- class function GetCryptSalt (const Salt : RawByteString ;
683- Format : TDECFormatClass):RawByteString ; virtual ;
687+ class function GetCryptSalt (const Salt : TBytes ;
688+ Format : TDECFormatClass):string ; virtual ;
684689 // / <summary>
685690 // / Returns the hash required for the crypt-like password storing
686691 // / in that format. If a salt etc. is needed that needs to be scepcified
@@ -698,9 +703,9 @@ TDECPasswordHash = class(TDECHashAuthentication)
698703 // / value of SaltIsRaw, the salt needs to specified in raw encoding or
699704 // / in the encoding used in the Crypt/BSD password storage string.
700705 // / </param>
701- // / <param name="SaltIsRaw ">
702- // / If true the passed salt value is a raw value. If false it is encoded
703- // / like in the Crypt/BSD password storage string .
706+ // / <param name="Salt ">
707+ // / Salt value used by the password hash calculation in binary raw format,
708+ // / means not Radix64 encoded or so .
704709 // / </param>
705710 // / <param name="Format">
706711 // / Format class for formatting the output
@@ -709,11 +714,10 @@ TDECPasswordHash = class(TDECHashAuthentication)
709714 // / Returns an empty string if the the algorithm on which this is being
710715 // / used is not a Crypt/BSD compatible password hash algorithm.
711716 // / </returns>
712- class function GetCryptHash (const Password : RawByteString;
713- const Params : RawByteString;
714- const Salt : RawByteString;
715- SaltIsRaw : Boolean;
716- Format : TDECFormatClass):RawByteString; virtual ;
717+ class function GetCryptHash (const Password : string;
718+ const Params : string;
719+ const Salt : TBytes;
720+ Format : TDECFormatClass):string; virtual ;
717721 { $EndRegion}
718722 public
719723 // / <summary>
@@ -789,10 +793,10 @@ TDECPasswordHash = class(TDECHashAuthentication)
789793 // / </exception>
790794 class function GetDigestInCryptFormat (
791795 const Password : RawByteString;
792- const Params : RawByteString ;
793- const Salt : RawByteString ;
796+ const Params : string ;
797+ const Salt : string ;
794798 SaltIsRaw : Boolean;
795- Format : TDECFormatClass):RawByteString ; virtual ;
799+ Format : TDECFormatClass):string ; virtual ;
796800
797801// /// <summary>
798802// /// Calculates a passwort hash for the given password and returns it in
@@ -1479,27 +1483,29 @@ procedure TDECPasswordHash.SetSalt(const Value: TBytes);
14791483 FSalt := Value ;
14801484end ;
14811485
1482- class function TDECPasswordHash.GetCryptID : RawByteString ;
1486+ class function TDECPasswordHash.GetCryptID : string ;
14831487begin
14841488 Result := ' ' ;
14851489end ;
14861490
14871491class function TDECPasswordHash.GetCryptParams (
1488- const Params : RawByteString ;
1489- Format : TDECFormatClass): RawByteString ;
1492+ const Params : string ;
1493+ Format : TDECFormatClass): string ;
14901494begin
14911495 Result := ' ' ;
14921496end ;
14931497
1494- class function TDECPasswordHash.GetCryptSalt (const Salt : RawByteString ;
1495- Format : TDECFormatCLass): RawByteString ;
1498+ class function TDECPasswordHash.GetCryptSalt (const Salt : TBytes ;
1499+ Format : TDECFormatCLass): string ;
14961500var
14971501 FormattedSalt : TBytes;
14981502begin
1499- FormattedSalt := Format.Encode(BytesOf(Salt));
1500- SetLength(Result, Length(FormattedSalt) + 1 );
1501- Move(FormattedSalt[0 ], Result[Low(Result) + 1 ], Length(FormattedSalt));
1502- Result[Low(Result)] := ' $' ;
1503+ FormattedSalt := Format.Encode(Salt);
1504+ // SetLength(Result, Length(FormattedSalt) + 1);
1505+ // Move(FormattedSalt[0], Result[Low(Result) + 1], Length(FormattedSalt));
1506+ // Result[Low(Result)] := '$';
1507+
1508+ Result := ' $' + TEncoding.ASCII.GetString(FormattedSalt);
15031509end ;
15041510
15051511class function TDECPasswordHash.ClassByCryptIdentity (
@@ -1527,24 +1533,31 @@ class function TDECPasswordHash.ClassByCryptIdentity(
15271533 [Identity]);
15281534end ;
15291535
1536+ procedure TDECPasswordHash.DoDone ;
1537+ begin
1538+ inherited ;
1539+
1540+ ProtectBuffer(FSalt, SizeOf(FSalt));
1541+ SetLength(FSalt, 0 );
1542+ end ;
1543+
15301544class function TDECPasswordHash.GetCryptHash (
1531- const Password : RawByteString;
1532- const Params : RawByteString;
1533- const Salt : RawByteString;
1534- SaltIsRaw : Boolean;
1535- Format : TDECFormatClass): RawByteString;
1545+ const Password : string;
1546+ const Params : string;
1547+ const Salt : TBytes;
1548+ Format : TDECFormatClass): string;
15361549begin
15371550 Result := ' ' ;
15381551end ;
15391552
15401553class function TDECPasswordHash.GetDigestInCryptFormat (
15411554 const Password : RawByteString;
1542- const Params : RawByteString ;
1543- const Salt : RawByteString ;
1555+ const Params : string ;
1556+ const Salt : string ;
15441557 SaltIsRaw : Boolean;
1545- Format : TDECFormatClass): RawByteString ;
1558+ Format : TDECFormatClass): string ;
15461559var
1547- SaltStr : RawByteString ;
1560+ SaltBytes : TBytes ;
15481561begin
15491562 // generic format used by Crypt, but not every algorithm sticks 100% to it
15501563 // $<id>[$<param>=<value>(,<param>=<value>)*][$<salt>[$<hash>]]
@@ -1554,13 +1567,13 @@ class function TDECPasswordHash.GetDigestInCryptFormat(
15541567 if (Result <> ' ' ) then
15551568 begin
15561569 if SaltIsRaw then
1557- SaltStr := Salt
1570+ SaltBytes := TEncoding.UTF8.GetBytes( Salt)
15581571 else
1559- SaltStr := Format.Decode(salt );
1572+ SaltBytes := Format.Decode(TEncoding.UTF8.GetBytes(Salt) );
15601573
15611574 Result := Result + GetCryptParams(Params, Format) +
1562- GetCryptSalt(SaltStr , Format) +
1563- GetCryptHash(Password, Params, Salt, SaltIsRaw , Format);
1575+ GetCryptSalt(SaltBytes , Format) +
1576+ GetCryptHash(Password, Params, SaltBytes , Format);
15641577 end ;
15651578end ;
15661579
0 commit comments