Comments (2)
Hello @Noobaxx apologies for the late response, just seeing this issue now.
there were a couple of issues with your original code.
you can find the C# code below and the updated Delphi one that produces same result as the C# one.
// See https://aka.ms/new-console-template for more information
using Microsoft.AspNetCore.Cryptography.KeyDerivation;
static string HashUsingPbkdf2(string password, byte[] salt)
{
byte[] derivedKey = KeyDerivation.Pbkdf2(password, salt, KeyDerivationPrf.HMACSHA256, iterationCount: 100000, 32);
return Convert.ToBase64String(derivedKey);
}
var salt = new byte[] { 1, 2, 3, 4, 5 };
var saltAsBase64String = Convert.ToBase64String(salt);
var saltStringAsBytes = Convert.FromBase64String(saltAsBase64String);
Console.WriteLine(HashUsingPbkdf2("1, 2, 3, 4, 5", saltStringAsBytes));
Console.ReadLine();
program Project1;
{$APPTYPE CONSOLE}
{$R *.res}
uses
HlpHashFactory,
HlpIHash,
HlpIHashInfo,
System.SysUtils,
System.NetEncoding;
function HashUsingPbkdf2(Password: string; Salt: TBytes): string;
var
PBKDF2: IPBKDF2_HMAC;
PassBytes, derivedKey: TBytes;
HashInstance: IHash;
begin
PassBytes := TEncoding.UTF8.GetBytes(Password);
HashInstance := THashFactory.TCrypto.CreateSHA2_256();
PBKDF2 := TKDF.TPBKDF2_HMAC.CreatePBKDF2_HMAC(HashInstance, PassBytes,
Salt, 100000);
derivedKey := PBKDF2.GetBytes(32);
Result := TBase64Encoding.Base64.EncodeBytesToString(derivedKey);
end;
begin
var
salt, saltStringAsBytes: TBytes;
var
saltAsBase64String: string;
try
{ TODO -oUser -cConsole Main : Insert code here }
salt := TBytes.Create(1, 2, 3, 4, 5);
saltAsBase64String := TBase64Encoding.Base64.EncodeBytesToString(salt);
saltStringAsBytes := TBase64Encoding.Base64.DecodeStringToBytes(saltAsBase64String);
Writeln(saltAsBase64String);
Writeln(HashUsingPbkdf2('1, 2, 3, 4, 5', saltStringAsBytes));
Readln;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
from hashlib4pascal.
Thank you very much.
I now understand my mistakes
from hashlib4pascal.
Related Issues (19)
- Custom Stop processing HOT 1
- Line 156 of HlpHashResult - Missing ConvertBytesToString HOT 2
- Quick Start and Document needed HOT 8
- Example needed HOT 6
- Code example? HOT 2
- error in readme.md missing "RIPEMD 160" HOT 1
- A little help needed please
- Processing data in chunks (Are my assumptions correct)? HOT 3
- Great library but Blake2SP is very slow HOT 4
- Adding xxHash XXH128 (SSE2) and\or XXH3 (SSE2) HOT 2
- Resourcestrings are in title caps HOT 6
- Encoding problems HOT 2
- CRC8 Exception HOT 1
- Create a release to use with boss Dependency Manager
- HlpTiger.pas F2084 Internal Error: URW1147 HOT 6
- Help needed trying to figure hash method HOT 9
- FPC 3.3.1: Doesn't compile HOT 3
- SHA-256 With RSA and MGF1 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hashlib4pascal.