Skip to content

Commit 049a159

Browse files
author
Vinod Gaur JD
committed
certificate related
1 parent 03372ca commit 049a159

File tree

76 files changed

+6722
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+6722
-4
lines changed

about/index.html

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,88 @@ <h5 class="modal-title" id="exampleModalLabel">
451451
</div>
452452
</div>
453453

454+
<!-- encryption decryption methods-->
455+
<script>
456+
function toBase64Url(uint8Array) {
457+
let binary = "";
458+
for (let b of uint8Array) binary += String.fromCharCode(b);
459+
return btoa(binary)
460+
.replace(/\+/g, "-")
461+
.replace(/\//g, "_")
462+
.replace(/=+$/, "");
463+
}
464+
465+
function fromBase64Url(base64Url) {
466+
base64Url = base64Url
467+
.replace(/-/g, "+")
468+
.replace(/_/g, "/");
469+
470+
// pad length to divide by 4
471+
while (base64Url.length % 4) base64Url += "=";
472+
473+
const binary = atob(base64Url);
474+
const bytes = new Uint8Array(binary.length);
475+
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
476+
return bytes;
477+
}
478+
479+
async function encryptData(jsonStr, keyText = "1234567890123456") {
480+
const enc = new TextEncoder();
481+
const iv = crypto.getRandomValues(new Uint8Array(12));
482+
483+
const key = await crypto.subtle.importKey(
484+
"raw",
485+
enc.encode(keyText),
486+
"AES-GCM",
487+
false,
488+
["encrypt"]
489+
);
490+
491+
const encrypted = await crypto.subtle.encrypt(
492+
{ name: "AES-GCM", iv },
493+
key,
494+
enc.encode(jsonStr)
495+
);
496+
497+
const cipherBytes = new Uint8Array(encrypted);
498+
499+
// Combine IV + ciphertext
500+
const combined = new Uint8Array(iv.length + cipherBytes.length);
501+
combined.set(iv, 0);
502+
combined.set(cipherBytes, iv.length);
503+
504+
return toBase64Url(combined); // <-- URL safe
505+
}
506+
507+
async function decryptData(urlSafeStr, keyText = "1234567890123456") {
508+
const enc = new TextEncoder();
509+
const bytes = fromBase64Url(urlSafeStr);
510+
511+
const iv = bytes.slice(0, 12);
512+
const encrypted = bytes.slice(12);
513+
514+
const key = await crypto.subtle.importKey(
515+
"raw",
516+
enc.encode(keyText),
517+
"AES-GCM",
518+
false,
519+
["decrypt"]
520+
);
521+
522+
const decrypted = await crypto.subtle.decrypt(
523+
{ name: "AES-GCM", iv },
524+
key,
525+
encrypted
526+
);
527+
528+
return new TextDecoder().decode(decrypted);
529+
}
530+
531+
function getLoggedInUserName(){
532+
return localStorage.getItem("username");
533+
}
534+
535+
</script>
454536

455537
<script type="module" src="/staticfiles/db/dbconfig.js"></script>
456538
<script type="module" src="/staticfiles/script.js"></script>

apply/cv_upload/index.html

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,88 @@ <h5 class="modal-title" id="exampleModalLabel">
473473
</div>
474474
</div>
475475

476+
<!-- encryption decryption methods-->
477+
<script>
478+
function toBase64Url(uint8Array) {
479+
let binary = "";
480+
for (let b of uint8Array) binary += String.fromCharCode(b);
481+
return btoa(binary)
482+
.replace(/\+/g, "-")
483+
.replace(/\//g, "_")
484+
.replace(/=+$/, "");
485+
}
486+
487+
function fromBase64Url(base64Url) {
488+
base64Url = base64Url
489+
.replace(/-/g, "+")
490+
.replace(/_/g, "/");
491+
492+
// pad length to divide by 4
493+
while (base64Url.length % 4) base64Url += "=";
494+
495+
const binary = atob(base64Url);
496+
const bytes = new Uint8Array(binary.length);
497+
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
498+
return bytes;
499+
}
500+
501+
async function encryptData(jsonStr, keyText = "1234567890123456") {
502+
const enc = new TextEncoder();
503+
const iv = crypto.getRandomValues(new Uint8Array(12));
504+
505+
const key = await crypto.subtle.importKey(
506+
"raw",
507+
enc.encode(keyText),
508+
"AES-GCM",
509+
false,
510+
["encrypt"]
511+
);
512+
513+
const encrypted = await crypto.subtle.encrypt(
514+
{ name: "AES-GCM", iv },
515+
key,
516+
enc.encode(jsonStr)
517+
);
518+
519+
const cipherBytes = new Uint8Array(encrypted);
520+
521+
// Combine IV + ciphertext
522+
const combined = new Uint8Array(iv.length + cipherBytes.length);
523+
combined.set(iv, 0);
524+
combined.set(cipherBytes, iv.length);
525+
526+
return toBase64Url(combined); // <-- URL safe
527+
}
528+
529+
async function decryptData(urlSafeStr, keyText = "1234567890123456") {
530+
const enc = new TextEncoder();
531+
const bytes = fromBase64Url(urlSafeStr);
532+
533+
const iv = bytes.slice(0, 12);
534+
const encrypted = bytes.slice(12);
535+
536+
const key = await crypto.subtle.importKey(
537+
"raw",
538+
enc.encode(keyText),
539+
"AES-GCM",
540+
false,
541+
["decrypt"]
542+
);
543+
544+
const decrypted = await crypto.subtle.decrypt(
545+
{ name: "AES-GCM", iv },
546+
key,
547+
encrypted
548+
);
549+
550+
return new TextDecoder().decode(decrypted);
551+
}
552+
553+
function getLoggedInUserName(){
554+
return localStorage.getItem("username");
555+
}
556+
557+
</script>
476558

477559
<script type="module" src="/staticfiles/db/dbconfig.js"></script>
478560
<script type="module" src="/staticfiles/script.js"></script>

apply/index.html

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,88 @@ <h5 class="modal-title" id="exampleModalLabel">
559559
</div>
560560
</div>
561561

562+
<!-- encryption decryption methods-->
563+
<script>
564+
function toBase64Url(uint8Array) {
565+
let binary = "";
566+
for (let b of uint8Array) binary += String.fromCharCode(b);
567+
return btoa(binary)
568+
.replace(/\+/g, "-")
569+
.replace(/\//g, "_")
570+
.replace(/=+$/, "");
571+
}
572+
573+
function fromBase64Url(base64Url) {
574+
base64Url = base64Url
575+
.replace(/-/g, "+")
576+
.replace(/_/g, "/");
577+
578+
// pad length to divide by 4
579+
while (base64Url.length % 4) base64Url += "=";
580+
581+
const binary = atob(base64Url);
582+
const bytes = new Uint8Array(binary.length);
583+
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
584+
return bytes;
585+
}
586+
587+
async function encryptData(jsonStr, keyText = "1234567890123456") {
588+
const enc = new TextEncoder();
589+
const iv = crypto.getRandomValues(new Uint8Array(12));
590+
591+
const key = await crypto.subtle.importKey(
592+
"raw",
593+
enc.encode(keyText),
594+
"AES-GCM",
595+
false,
596+
["encrypt"]
597+
);
598+
599+
const encrypted = await crypto.subtle.encrypt(
600+
{ name: "AES-GCM", iv },
601+
key,
602+
enc.encode(jsonStr)
603+
);
604+
605+
const cipherBytes = new Uint8Array(encrypted);
606+
607+
// Combine IV + ciphertext
608+
const combined = new Uint8Array(iv.length + cipherBytes.length);
609+
combined.set(iv, 0);
610+
combined.set(cipherBytes, iv.length);
611+
612+
return toBase64Url(combined); // <-- URL safe
613+
}
614+
615+
async function decryptData(urlSafeStr, keyText = "1234567890123456") {
616+
const enc = new TextEncoder();
617+
const bytes = fromBase64Url(urlSafeStr);
618+
619+
const iv = bytes.slice(0, 12);
620+
const encrypted = bytes.slice(12);
621+
622+
const key = await crypto.subtle.importKey(
623+
"raw",
624+
enc.encode(keyText),
625+
"AES-GCM",
626+
false,
627+
["decrypt"]
628+
);
629+
630+
const decrypted = await crypto.subtle.decrypt(
631+
{ name: "AES-GCM", iv },
632+
key,
633+
encrypted
634+
);
635+
636+
return new TextDecoder().decode(decrypted);
637+
}
638+
639+
function getLoggedInUserName(){
640+
return localStorage.getItem("username");
641+
}
642+
643+
</script>
562644

563645
<script type="module" src="/staticfiles/db/dbconfig.js"></script>
564646
<script type="module" src="/staticfiles/script.js"></script>

apply/thanks/index.html

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,88 @@ <h5 class="modal-title" id="exampleModalLabel">
407407
</div>
408408
</div>
409409

410+
<!-- encryption decryption methods-->
411+
<script>
412+
function toBase64Url(uint8Array) {
413+
let binary = "";
414+
for (let b of uint8Array) binary += String.fromCharCode(b);
415+
return btoa(binary)
416+
.replace(/\+/g, "-")
417+
.replace(/\//g, "_")
418+
.replace(/=+$/, "");
419+
}
420+
421+
function fromBase64Url(base64Url) {
422+
base64Url = base64Url
423+
.replace(/-/g, "+")
424+
.replace(/_/g, "/");
425+
426+
// pad length to divide by 4
427+
while (base64Url.length % 4) base64Url += "=";
428+
429+
const binary = atob(base64Url);
430+
const bytes = new Uint8Array(binary.length);
431+
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
432+
return bytes;
433+
}
434+
435+
async function encryptData(jsonStr, keyText = "1234567890123456") {
436+
const enc = new TextEncoder();
437+
const iv = crypto.getRandomValues(new Uint8Array(12));
438+
439+
const key = await crypto.subtle.importKey(
440+
"raw",
441+
enc.encode(keyText),
442+
"AES-GCM",
443+
false,
444+
["encrypt"]
445+
);
446+
447+
const encrypted = await crypto.subtle.encrypt(
448+
{ name: "AES-GCM", iv },
449+
key,
450+
enc.encode(jsonStr)
451+
);
452+
453+
const cipherBytes = new Uint8Array(encrypted);
454+
455+
// Combine IV + ciphertext
456+
const combined = new Uint8Array(iv.length + cipherBytes.length);
457+
combined.set(iv, 0);
458+
combined.set(cipherBytes, iv.length);
459+
460+
return toBase64Url(combined); // <-- URL safe
461+
}
462+
463+
async function decryptData(urlSafeStr, keyText = "1234567890123456") {
464+
const enc = new TextEncoder();
465+
const bytes = fromBase64Url(urlSafeStr);
466+
467+
const iv = bytes.slice(0, 12);
468+
const encrypted = bytes.slice(12);
469+
470+
const key = await crypto.subtle.importKey(
471+
"raw",
472+
enc.encode(keyText),
473+
"AES-GCM",
474+
false,
475+
["decrypt"]
476+
);
477+
478+
const decrypted = await crypto.subtle.decrypt(
479+
{ name: "AES-GCM", iv },
480+
key,
481+
encrypted
482+
);
483+
484+
return new TextDecoder().decode(decrypted);
485+
}
486+
487+
function getLoggedInUserName(){
488+
return localStorage.getItem("username");
489+
}
490+
491+
</script>
410492

411493
<script type="module" src="/staticfiles/db/dbconfig.js"></script>
412494
<script type="module" src="/staticfiles/script.js"></script>

0 commit comments

Comments
 (0)