procedure TForm2.Button3Click(Sender: TObject); var hashed:string; begin hashed:=TkbmMWHashSHA256.HashAsString('mypassword','somesaltvalue'); Label1.Caption:='TkbmMWHashSHA256='+hashed; end; procedure TForm2.Button4Click(Sender: TObject); var hashed:string; LSHA2: THashSHA2; begin LSHA2 := THashSHA2.Create;//(SHA256); LSHA2.Update('somesaltvalue'); LSHA2.Update('mypassword'); hashed:=LSHA2.HashAsString; Label2.Caption:='Delphi LSHA2.HashAsString='+hashed.ToUpper; end; end.
自Delphi 10.2,在System.Hash單元中,新增了HashSHA256等支持,而在最新的kbmMW 5.06 beta版中,在kbmMWCipherHash單元中,也進一步完善對Hash256等支持,有何不一樣呢?加密
例以下面這行代碼,直接將給定字符串加salt後獲得加密結果,若是基於Delphi原生hash256怎麼實現?spa
hashed:=TkbmMWHashSHA256.HashAsString('mypassword','somesaltvalue');
困擾了半天,最終在xalion幫助下,才知道如何實現。code
LSHA2: THashSHA2; begin LSHA2 := THashSHA2.Create;//(SHA256); LSHA2.Update('somesaltvalue'); LSHA2.Update('mypassword'); hashed:=LSHA2.HashAsString; Label2.Caption:='Delphi LSHA2.HashAsString='+hashed.ToUpper; end;
仍是kbmMW實現的好,一行代碼換成Delphi原生要寫這麼多句。下圖是運行結果:orm
環境:Delphi 10.2.3+kbmMW 5.06.01 beta.blog