-
Notifications
You must be signed in to change notification settings - Fork 0
/
pbkdf2.html
709 lines (668 loc) · 22.7 KB
/
pbkdf2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>PBKDF2 Hash Generator and Verifier Tool</title>
<meta
name="description"
content="A secure PBKDF2 hash generator and verifier tool to enhance data protection. Generate and verify PBKDF2 hashes for your passwords and sensitive data online."
/>
<meta
name="keywords"
content="pbkdf2, hash generator, hash verifier, data encryption, secure passwords, pbkdf2 hashing"
/>
<link rel="canonical" href="https://bcrypt.tools/pbkdf2" />
<!-- Favicon -->
<link
rel="apple-touch-icon"
sizes="180x180"
href="/images/favicon/apple-touch-icon.png"
/>
<link
rel="icon"
type="image/png"
sizes="32x32"
href="/images/favicon/favicon-32x32.png"
/>
<link
rel="icon"
type="image/png"
sizes="16x16"
href="/images/favicon/favicon-16x16.png"
/>
<link rel="manifest" href="/site.webmanifest" />
<link
rel="mask-icon"
href="/images/favicon/safari-pinned-tab.svg"
color="#5bbad5"
/>
<link rel="shortcut icon" href="/images/favicon/favicon.ico" />
<meta name="msapplication-TileColor" content="#ffffff" />
<meta name="msapplication-config" content="/browserconfig.xml" />
<meta name="theme-color" content="#ffffff" />
<!-- Facebook Meta Tags -->
<meta property="og:url" content="https://bcrypt.tools/pbkdf2" />
<meta property="og:type" content="website" />
<meta
property="og:title"
content="PBKDF2 Hash Generator and Verifier Tool"
/>
<meta
property="og:description"
content="Securely generate and verify PBKDF2 hashes online."
/>
<meta
property="og:image"
content="https://bcrypt.tools/images/social.png"
/>
<meta
property="og:image:alt"
content="An image featuring the text 'bcrypt.tools' in white on a blue background."
/>
<!-- Google Meta Tags -->
<meta name="google-adsense-account" content="ca-pub-7390955753222656" />
<script
async
src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-7390955753222656"
crossorigin="anonymous"
></script>
<!-- Twitter Meta Tags -->
<meta name="twitter:card" content="summary_large_image" />
<meta property="twitter:url" content="https://bcrypt.tools/pbkdf2" />
<meta
name="twitter:title"
content="PBKDF2 Hash Generator and Verifier Tool"
/>
<meta
name="twitter:description"
content="Securely generate and verify PBKDF2 hashes online."
/>
<meta
name="twitter:image"
content="https://bcrypt.tools/images/social.png"
/>
<meta
property="twitter:image:alt"
content="An image featuring the text 'bcrypt.tools' in white on a blue background."
/>
<!-- Tailwind CSS -->
<script src="https://cdn.tailwindcss.com"></script>
<script>
const onSubmitGenerateHash = async (event) => {
event.preventDefault();
const text = document.getElementById("input-text").value;
const salt = document.getElementById("salt-text").value;
const iterations = parseInt(
document.getElementById("iterations-count").value,
10
);
if (!text || !salt || !iterations) {
showAlert("All fields are required!");
return;
}
try {
const encodedText = new TextEncoder().encode(text);
const encodedSalt = new TextEncoder().encode(salt);
const keyMaterial = await crypto.subtle.importKey(
"raw",
encodedText,
{ name: "PBKDF2" },
false,
["deriveBits", "deriveKey"]
);
const key = await crypto.subtle.deriveKey(
{
name: "PBKDF2",
salt: encodedSalt,
iterations: iterations,
hash: "SHA-256",
},
keyMaterial,
{ name: "AES-GCM", length: 256 },
true,
["encrypt", "decrypt"]
);
const exportedKey = await crypto.subtle.exportKey("raw", key);
const hash = Array.from(new Uint8Array(exportedKey))
.map((b) => b.toString(16).padStart(2, "0"))
.join("");
document.getElementById("hash-output").value = hash;
document
.getElementById("hash-output")
.parentElement.classList.remove("hidden");
} catch (error) {
console.error(error);
showAlert("Error generating the hash!");
}
};
const onSubmitCompareHash = async (event) => {
event.preventDefault();
const data = document.getElementById("data-to-compare").value;
const salt = document.getElementById("salt-to-compare").value;
const iterations = parseInt(
document.getElementById("iterations-to-compare").value,
10
);
const hash = document.getElementById("hash-to-compare").value;
if (!data || !salt || !iterations || !hash) {
showAlert("All fields are required for comparison!");
return;
}
try {
const encodedText = new TextEncoder().encode(data);
const encodedSalt = new TextEncoder().encode(salt);
const keyMaterial = await crypto.subtle.importKey(
"raw",
encodedText,
{ name: "PBKDF2" },
false,
["deriveBits", "deriveKey"]
);
const derivedKey = await crypto.subtle.deriveKey(
{
name: "PBKDF2",
salt: encodedSalt,
iterations: iterations,
hash: "SHA-256",
},
keyMaterial,
{ name: "AES-GCM", length: 256 },
true,
["encrypt", "decrypt"]
);
const exportedKey = await crypto.subtle.exportKey("raw", derivedKey);
const derivedHash = Array.from(new Uint8Array(exportedKey))
.map((b) => b.toString(16).padStart(2, "0"))
.join("");
const isMatch = derivedHash === hash;
const resultElement = document.getElementById("compare-hash-result");
resultElement.textContent = isMatch ? "Match" : "Do not match";
resultElement.classList.remove(
"bg-green-100",
"text-green-800",
"bg-red-100",
"text-red-800",
"border-green-400",
"border-red-400"
);
if (isMatch) {
resultElement.classList.add(
"bg-green-100",
"text-green-800",
"border-green-400"
);
} else {
resultElement.classList.add(
"bg-red-100",
"text-red-800",
"border-red-400"
);
}
resultElement.style.display = "block";
} catch (error) {
console.error(error);
showAlert("Error comparing the hash!");
}
};
const copyToClipboard = () => {
const hashOutput = document.getElementById("hash-output");
navigator.clipboard
.writeText(hashOutput.value)
.then(() => showAlert("Hash copied to clipboard!"))
.catch((err) => console.error("Error copying to clipboard", err));
};
const pasteFromClipboard = () => {
navigator.clipboard
.readText()
.then((text) => {
const hashToCompareInput =
document.getElementById("hash-to-compare");
hashToCompareInput.value = text;
showAlert("Text pasted into the input!");
})
.catch((err) => {
console.error("Error pasting text from clipboard", err);
});
};
const showAlert = (message) => {
let existingAlert = document.querySelector(".alert-container");
if (existingAlert) {
existingAlert.remove();
}
const alertContainer = document.createElement("div");
alertContainer.textContent = message;
alertContainer.classList.add(
"alert-container",
"absolute",
"top-5",
"left-1/2",
"-translate-x-1/2",
"bg-blue-500",
"text-white",
"px-4",
"py-2",
"rounded",
"shadow-lg",
"transition-opacity",
"opacity-100"
);
document.body.appendChild(alertContainer);
setTimeout(() => {
alertContainer.classList.replace("opacity-100", "opacity-0");
}, 2500);
setTimeout(() => {
alertContainer.remove();
}, 3000);
};
const resetFirstForm = () => {
document.getElementById("generate-hash-form").reset();
document
.getElementById("hash-output")
.parentElement.classList.add("hidden");
};
const resetSecondForm = () => {
document.getElementById("compare-hash-form").reset();
document.getElementById("compare-hash-result").style.display = "none";
};
</script>
</head>
<body class="flex flex-col w-full bg-gray-100">
<div id="alert-container" class="hidden"></div>
<header class="bg-white p-4">
<a href="/" class="hover:underline">
<h1 class="text-2xl font-bold text-center mb-2">
Bcrypt.tools - PBKDF2 Hash Generator and Verifier Tool
</h1>
</a>
<p class="text-gray-600 text-center">
Easily generate and verify PBKDF2 hashes for your passwords and
sensitive data online.
</p>
<nav class="mt-4">
<ul class="flex flex-wrap justify-center space-x-4">
<li>
<a href="/" class="text-blue-500 hover:text-blue-700">Bcrypt</a>
</li>
<li>
<a href="/md4" class="text-blue-500 hover:text-blue-700">MD4</a>
</li>
<li>
<a href="/md5" class="text-blue-500 hover:text-blue-700">MD5</a>
</li>
<li>
<a href="/sha1" class="text-blue-500 hover:text-blue-700">SHA-1</a>
</li>
<li>
<a href="/sha256" class="text-blue-500 hover:text-blue-700"
>SHA-256</a
>
</li>
<li>
<a href="/sha512" class="text-blue-500 hover:text-blue-700"
>SHA-512</a
>
</li>
<li>
<a href="/pbkdf2" class="text-blue-500 hover:text-blue-700 active"
>PBKDF2</a
>
</li>
<li>
<a href="/argon2" class="text-blue-500 hover:text-blue-700"
>Argon2</a
>
</li>
<li>
<a href="/crc32" class="text-blue-500 hover:text-blue-700">CRC32</a>
</li>
<li>
<a href="/hmac" class="text-blue-500 hover:text-blue-700">HMAC</a>
</li>
</ul>
</nav>
</header>
<main class="mx-auto max-w-4xl p-4 flex flex-col gap-4">
<section id="hash-generator" class="bg-white border rounded-md p-4">
<h2 class="text-xl font-semibold mb-2">Encrypt</h2>
<p class="text-base mb-4 text-gray-700">
Generate a secure PBKDF2 hash from any plaintext for enhanced password
protection.
</p>
<form
id="generate-hash-form"
onsubmit="onSubmitGenerateHash(event);"
class="mb-6"
>
<input
type="text"
id="input-text"
name="plaintext"
placeholder="Plain Text"
class="input"
required
/>
<input
type="text"
id="salt-text"
name="salt"
placeholder="Salt"
class="input"
required
/>
<input
type="number"
id="iterations-count"
name="iterations"
placeholder="Iterations (default 1000)"
class="input"
min="1"
value="1000"
/>
<div class="flex flex-col sm:flex-row justify-between gap-2">
<button type="submit" class="button button-solid">
Generate Hash
</button>
<button
type="button"
class="button button-solid"
onclick="resetFirstForm()"
>
Reset
</button>
</div>
</form>
<div class="flex items-center gap-2 hidden mb-4">
<input
type="text"
id="hash-output"
class="input flex-1"
style="margin-bottom: 0px"
readonly
/>
<button onclick="copyToClipboard()" class="button button-outline">
Copy
</button>
</div>
<h2 class="text-xl font-semibold mb-2">Verify</h2>
<p class="text-base mb-4 text-gray-700">
Verify if a plaintext matches a specific PBKDF2 hash, ensuring secure
login validation.
</p>
<form id="compare-hash-form" onsubmit="onSubmitCompareHash(event);">
<input
type="text"
id="data-to-compare"
name="data-to-compare"
placeholder="Plain Text"
class="input"
required
/>
<input
type="text"
id="salt-to-compare"
name="salt"
placeholder="Salt"
class="input"
required
/>
<input
type="number"
id="iterations-to-compare"
name="iterations"
placeholder="Iterations"
class="input"
required
/>
<div class="flex items-center gap-2 mb-4">
<input
type="text"
id="hash-to-compare"
name="hash-to-compare"
placeholder="Hash"
class="input"
style="margin-bottom: 0px"
required
/>
<button
type="button"
onclick="pasteFromClipboard()"
class="button button-outline"
>
Paste
</button>
</div>
<div class="flex flex-col sm:flex-row justify-between gap-2">
<button type="submit" class="button button-solid">
Verify Hash
</button>
<button
type="button"
class="button button-solid"
onclick="resetSecondForm()"
>
Reset
</button>
</div>
</form>
<div
id="compare-hash-result"
class="result"
style="display: none"
></div>
</section>
<section id="faq" class="flex flex-col gap-4">
<h2 class="text-xl font-semibold">FAQ - Frequently Asked Questions</h2>
<!-- Why PBKDF2? -->
<section
id="about-pbkdf2"
class="flex flex-col bg-white border rounded-md p-4 gap-2"
>
<h3 class="text-lg font-semibold">Why PBKDF2?</h3>
<p class="text-base text-gray-700">
PBKDF2 (Password-Based Key Derivation Function 2) is a key
derivation function designed to secure passwords by using a
cryptographic hash, a salt, and multiple iterations. It is used to
protect sensitive information like passwords and cryptographic keys
by making the hash computation process slower and more resistant to
brute-force attacks.
</p>
</section>
<!-- Explanation of Fields -->
<section id="field-explanation" class="bg-white border rounded-md p-4">
<h3 class="text-lg font-semibold mb-2">Explanation of Fields</h3>
<!-- Password -->
<section class="mb-4">
<h4 class="text-md font-semibold">Password</h4>
<p class="text-base text-gray-700">
This is the input string that will be hashed. It must be provided
and cannot be empty. The password is used as part of the key
derivation process, and it is crucial to choose a strong password
to ensure security.
</p>
<p class="text-base text-red-500">
Validation: The password field must be non-empty.
</p>
</section>
<!-- Salt -->
<section class="mb-4">
<h4 class="text-md font-semibold">Salt</h4>
<p class="text-base text-gray-700">
Salt is a random value added to the password before hashing. The
purpose of salt is to prevent attackers from using precomputed
tables (e.g., rainbow tables) to crack the password. Each password
should have a unique salt.
</p>
<p class="text-base text-red-500">
Validation: Salt must be provided and should be long enough (at
least 8 bytes) to provide adequate protection.
</p>
</section>
<!-- Iterations -->
<section class="mb-4">
<h4 class="text-md font-semibold">Iterations</h4>
<p class="text-base text-gray-700">
This value controls how many times the PBKDF2 function is applied
to the password. A higher number of iterations increases the
computational cost and makes the hash harder to crack using brute
force, but it also takes more time to compute.
</p>
<p class="text-base text-red-500">
Validation: Iterations must be a positive integer. The default
value is 1000, but you can increase this number for greater
security.
</p>
</section>
<!-- Hash -->
<section class="mb-4">
<h4 class="text-md font-semibold">Hash</h4>
<p class="text-base text-gray-700">
The generated hash is the final output of the PBKDF2 process. It
is derived from the password, salt, and iterations. This value is
used for securely storing passwords and validating users during
login.
</p>
<p class="text-base text-red-500">
Note: The hash is encoded and displayed as a hexadecimal string.
</p>
</section>
<!-- Compare Hash -->
<section class="mb-4">
<h4 class="text-md font-semibold">Compare Hash</h4>
<p class="text-base text-gray-700">
To verify a password, the provided plain text password and salt
are rehashed using the same number of iterations and compared to
the stored hash. If the hashes match, the password is correct.
</p>
<p class="text-base text-red-500">
Validation: All fields (plain text, salt, and iterations) must
match the original hash parameters to successfully verify the
password.
</p>
</section>
</section>
<section id="hash-info" class="bg-white border rounded-md p-4">
<h3 class="text-lg font-semibold mb-2">Hash Details</h3>
<p class="text-base text-gray-700 mb-4">
PBKDF2 uses a combination of salt, iteration count, and hash length
to generate a strong and secure hash. It is often used in password
hashing and key derivation in various security protocols and
systems.
</p>
</section>
</section>
<section id="resources" class="flex flex-col gap-4">
<h2 class="text-xl font-semibold">Relevant Links</h2>
<div class="grid grid-cols-2 gap-4">
<div class="p-4 border rounded bg-white">
<a
href="https://en.wikipedia.org/wiki/PBKDF2"
target="_blank"
rel="external noopener noreferrer"
aria-label="Wikipedia page for PBKDF2 - External link"
class="text-blue-600 hover:text-blue-800 hover:underline"
>Wikipedia: PBKDF2</a
>
</div>
<div class="p-4 border rounded bg-white">
<a
href="https://tools.ietf.org/html/rfc2898"
target="_blank"
rel="external noopener noreferrer"
aria-label="PBKDF2 Specification RFC 2898 - External link"
class="text-blue-600 hover:text-blue-800 hover:underline"
>PBKDF2 Specification (RFC 2898)</a
>
</div>
</div>
</section>
</main>
<footer class="bg-gray-800 text-white p-4 mt-8">
<div
class="flex flex-col sm:flex-row max-w-6xl mx-auto flex flex-wrap justify-between items-center"
>
<div class="p-2 order-2 sm:order-first">
© 2024
<a
href="/"
class="text-white hover:text-gray-400"
rel="noopener noreferrer"
>Bcrypt.tools</a
>. All rights reserved.
</div>
<div class="p-2">
Email:
<a
href="mailto:contact@bcrypt.tools"
class="text-white hover:text-gray-400"
rel="noopener noreferrer"
>contact@bcrypt.tools</a
>
</div>
<div class="p-2">
<a
href="/privacy-policy"
class="text-white hover:text-gray-400"
rel="noopener noreferrer"
>Privacy Policy</a
>
|
<a
href="/terms-of-use"
class="text-white hover:text-gray-400"
rel="noopener noreferrer"
>Terms of Use</a
>
</div>
</div>
</footer>
<style>
.input {
width: 100%;
padding: 0.5rem;
margin-bottom: 1rem;
border: 1px solid #ddd;
border-radius: 0.375rem;
box-shadow: inset 0 2px 4px 0 rgba(0, 0, 0, 0.05);
}
.button {
padding: 0.5rem 1rem;
border-radius: 0.375rem;
font-weight: 600;
text-align: center;
cursor: pointer;
transition: all 0.3s ease;
}
.button-solid {
background-color: #4f46e5;
color: white;
border: 2px solid transparent;
}
.button-outline {
background-color: transparent;
color: #4f46e5;
border: 2px solid #4f46e5;
}
.button-outline:hover {
background-color: #4f46e5;
color: white;
}
.result {
padding: 0.5rem;
border-radius: 0.375rem;
margin-top: 1rem;
border-width: 1px;
}
.active {
font-weight: bold;
text-decoration: underline;
}
code {
padding: 0.25rem;
border-radius: 0.25rem;
word-break: break-all;
background-color: #f3f4f6;
}
</style>
</body>
</html>