kbmMW TkbmMWHashSHA256与Delphi 10.2 THashSHA2算出相同的结果
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怎么实现?
hashed:=TkbmMWHashSHA256.HashAsString('mypassword','somesaltvalue');
困扰了半天,最终在xalion帮助下,才知道如何实现。
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原生要写这么多句。下图是运行结果:
环境:Delphi 10.2.3+kbmMW 5.06.01 beta.