@@ -1543,7 +1543,7 @@ <h2 style="margin-top: 4px; margin-bottom: 5px; font-size: 20px">
1543
1543
</ script >
1544
1544
1545
1545
< button
1546
- onclick ="encryptText();scrollToTopFully(); "
1546
+ onclick ="encryptText(); "
1547
1547
class ="ttClass "
1548
1548
data-tooltip ="(Web Crypto API, AES-GCM) Enter text to encrypt, click Encrypt, then enter a password when
1549
1549
prompted. A base64 representation of the encrypted data will be
@@ -1553,7 +1553,7 @@ <h2 style="margin-top: 4px; margin-bottom: 5px; font-size: 20px">
1553
1553
</ button >
1554
1554
1555
1555
< button
1556
- onclick ="decryptText();scrollToTopFully(); "
1556
+ onclick ="decryptText(); "
1557
1557
class ="ttClass "
1558
1558
data-tooltip ="Enter text to decrypt, click Decrypt and then when
1559
1559
prompted, enter the same password as used for
@@ -1588,12 +1588,16 @@ <h2 style="margin-top: 4px; margin-bottom: 5px; font-size: 20px">
1588
1588
// let encryptedDataOut = window.document.getElementById("encryptedData");
1589
1589
let encryptedDataOut =
1590
1590
window . document . getElementById ( "textMainArea" ) ;
1591
+ // Prompt for the password
1592
+
1591
1593
const password = window . prompt ( "Password" ) ;
1592
1594
const encryptedData = await encryptData ( data , password ) ;
1593
1595
encryptedDataOut . value = encryptedData ;
1594
1596
}
1595
1597
1596
1598
async function decryptText ( ) {
1599
+ // Prompt for the password
1600
+
1597
1601
const password = window . prompt ( "Password" ) ;
1598
1602
// const encryptedData = window.document.getElementById("encryptedData").value;
1599
1603
const encryptedData =
@@ -1603,6 +1607,9 @@ <h2 style="margin-top: 4px; margin-bottom: 5px; font-size: 20px">
1603
1607
window . document . getElementById ( "textMainArea" ) ;
1604
1608
const decryptedData = await decryptData ( encryptedData , password ) ;
1605
1609
decryptedDataOut . value = decryptedData || "Decryption failed" ;
1610
+
1611
+ // added this to scroll back up, but only after prompt has been given, needed for mobile
1612
+ scrollToTopFully ( ) ;
1606
1613
}
1607
1614
1608
1615
const getPasswordKey = ( password ) =>
@@ -1685,7 +1692,7 @@ <h2 style="margin-top: 4px; margin-bottom: 5px; font-size: 20px">
1685
1692
</ script >
1686
1693
1687
1694
< button
1688
- onclick ="encryptFileStart();scrollToTopFully(); "
1695
+ onclick ="encryptFileStart(); "
1689
1696
class ="ttClass "
1690
1697
data-tooltip ="(Web Crypto API, AES-GCM) Select the File to process. Click Encrypt, then enter a password when
1691
1698
prompted. An encrypted file of the original will be downloaded. Note: Doesn't work on the Android app. "
@@ -1701,7 +1708,7 @@ <h2 style="margin-top: 4px; margin-bottom: 5px; font-size: 20px">
1701
1708
-->
1702
1709
1703
1710
< button
1704
- onclick ="decryptFileStart();scrollToTopFully(); "
1711
+ onclick ="decryptFileStart(); "
1705
1712
class ="ttClass "
1706
1713
data-tooltip ="Enter text to decrypt, click Decrypt and then when
1707
1714
prompted, enter the same password as used for
@@ -1712,82 +1719,6 @@ <h2 style="margin-top: 4px; margin-bottom: 5px; font-size: 20px">
1712
1719
1713
1720
<!-- -->
1714
1721
1715
- < div id ="operationModeContainer ">
1716
- < button
1717
- class ="clickbutton "
1718
- id ="selectEncrypt "
1719
- type ="button "
1720
- onclick ="showEncrypt(); "
1721
- >
1722
- Encrypt a File
1723
- </ button >
1724
- < button
1725
- class ="clickbutton "
1726
- id ="selectDncrypt "
1727
- type ="button "
1728
- onclick ="showDecrypt(); "
1729
- >
1730
- Decrypt a File
1731
- </ button >
1732
- </ div >
1733
-
1734
- < div id ="cypherContainer " class ="hidden ">
1735
- < table >
1736
- <!--<tr><td>Select File</td><td><input id="selectFile" type="file" aria-label="Select a file"></td><td id="selectFileHint">Select the File you'd like to process.</td></tr>-->
1737
- < tr >
1738
- < td > Password</ td >
1739
- < td >
1740
- < input
1741
- id ="mainPassword "
1742
- type ="password "
1743
- aria-label ="Enter password "
1744
- />
1745
- </ td >
1746
- < td id ="mainPasswordHint ">
1747
- Strong password, minumum length is 8 characters.
1748
- </ td >
1749
- </ tr >
1750
- < tr id ="trConfirmPassword ">
1751
- < td > Retype Password</ td >
1752
- < td >
1753
- < input
1754
- id ="confirmPassword "
1755
- type ="password "
1756
- aria-label ="Confirm password "
1757
- />
1758
- </ td >
1759
- < td id ="confirmPasswordHint ">
1760
- Retype your password from above to ensure you didn't mistype
1761
- it.
1762
- </ td >
1763
- </ tr >
1764
- </ table >
1765
- < button
1766
- id ="btnEncrypt "
1767
- class ="clickbutton green "
1768
- type ="button "
1769
- onclick ="encryptFile(); "
1770
- >
1771
- Encrypt
1772
- </ button >
1773
- < button
1774
- id ="btnDecrypt "
1775
- class ="clickbutton green "
1776
- type ="button "
1777
- onclick ="decryptFile(); "
1778
- >
1779
- Decrypt
1780
- </ button >
1781
- < button
1782
- id ="btnReload "
1783
- class ="clickbutton orange "
1784
- type ="button "
1785
- onclick ="javascript:location.reload(); "
1786
- >
1787
- Reload Page
1788
- </ button >
1789
- </ div >
1790
-
1791
1722
< script >
1792
1723
// https://github.com/hazelfazel/Web-Browser-Based-AES-GCM-File-Encryption-Decryption
1793
1724
@@ -1883,6 +1814,9 @@ <h2 style="margin-top: 4px; margin-bottom: 5px; font-size: 20px">
1883
1814
) ;
1884
1815
}
1885
1816
1817
+ // added this - Global variable to hold the password
1818
+ let mainPassword ;
1819
+
1886
1820
// added this
1887
1821
function encryptFileStart ( ) {
1888
1822
// trigger file upload of button click
@@ -1897,6 +1831,16 @@ <h2 style="margin-top: 4px; margin-bottom: 5px; font-size: 20px">
1897
1831
reader . onload = function ( event ) { } ;
1898
1832
// do this after upload
1899
1833
// call the actual encryption
1834
+
1835
+ // Prompt for the password
1836
+ // change all mainPassword.value to just mainPassword
1837
+ mainPassword = window . prompt ( "Password" ) ;
1838
+
1839
+ // added this to scroll back up, but only after prompt has been given, needed for mobile
1840
+ scrollToTopFully ( ) ;
1841
+
1842
+ //encryptFile();
1843
+ // Call the actual encryption with mainPassword as argument
1900
1844
encryptFile ( ) ;
1901
1845
1902
1846
reader . onerror = function ( event ) {
@@ -1921,8 +1865,7 @@ <h2 style="margin-top: 4px; margin-bottom: 5px; font-size: 20px">
1921
1865
//confirmPasswordHint.classList.remove("greenspan");
1922
1866
//confirmPasswordHint.classList.remove("redspan");
1923
1867
/*if ( ( mainPassword.value === confirmPassword.value) && ( mainPassword.value !== "" ) && ( mainPassword.value.length >= 8 ) ) {*/
1924
- // added this below, commented out surrounding if clause around this as well as } } else {, had to do this for both encrypt and decrypt
1925
- mainPassword . value = window . prompt ( "Password" ) ;
1868
+ // commented out surrounding if clause around this as well as } } else {, had to do this for both encrypt and decrypt
1926
1869
//confirmPasswordHint.classList.add("greenspan");
1927
1870
//logContainer.classList.remove("hidden");
1928
1871
try {
@@ -1939,7 +1882,8 @@ <h2 style="margin-top: 4px; margin-bottom: 5px; font-size: 20px">
1939
1882
) ;
1940
1883
//log.textContent += "\r\nsha-256 hash of plaintext file: " + arr2Hex(hashPlaintext);
1941
1884
//log.textContent += "\r\nderiving key from password and random salt ...";
1942
- let keyIv = await deriveKeyIv ( mainPassword . value , pbkdf2salt ) ;
1885
+ //let keyIv = await deriveKeyIv(mainPassword.value, pbkdf2salt);
1886
+ let keyIv = await deriveKeyIv ( mainPassword , pbkdf2salt ) ;
1943
1887
//console.log ( "pbkdf2salt: " + btoa(String.fromCharCode.apply(null, pbkdf2salt)) );
1944
1888
//log.textContent += "\r\npbkdf2salt: " + btoa(String.fromCharCode.apply(null, pbkdf2salt));
1945
1889
//log.textContent += "\r\nstarting to encrypt ...";
@@ -1993,6 +1937,16 @@ <h2 style="margin-top: 4px; margin-bottom: 5px; font-size: 20px">
1993
1937
reader . onload = function ( event ) { } ;
1994
1938
// do this after upload
1995
1939
// call the actual encryption
1940
+
1941
+ // Prompt for the password
1942
+ // change all mainPassword.value to just mainPassword
1943
+ mainPassword = window . prompt ( "Password" ) ;
1944
+
1945
+ // added this to scroll back up, but only after prompt has been given, needed for mobile
1946
+ scrollToTopFully ( ) ;
1947
+
1948
+ //encryptFile();
1949
+ // Call the actual encryption with mainPassword as argument
1996
1950
decryptFile ( ) ;
1997
1951
1998
1952
reader . onerror = function ( event ) {
@@ -2017,8 +1971,7 @@ <h2 style="margin-top: 4px; margin-bottom: 5px; font-size: 20px">
2017
1971
//mainPasswordHint.classList.remove("greenspan");
2018
1972
//mainPasswordHint.classList.remove("redspan");
2019
1973
/*if ( ( mainPassword.value !== "") && ( mainPassword.value.length >= 8 ) ) { */
2020
- // added this below, commented out surrounding if clause around this as well as } } else {, had to do this for both encrypt and decrypt
2021
- mainPassword . value = window . prompt ( "Password" ) ;
1974
+ // commented out surrounding if clause around this as well as } } else {, had to do this for both encrypt and decrypt
2022
1975
//mainPasswordHint.classList.add("greenspan");
2023
1976
//logContainer.classList.remove("hidden");
2024
1977
try {
@@ -2037,7 +1990,8 @@ <h2 style="margin-top: 4px; margin-bottom: 5px; font-size: 20px">
2037
1990
//log.textContent += "\r\nderiving key from password and salt provided in encrypted file ...";
2038
1991
pbkdf2salt = new Uint8Array ( file . slice ( 0 , 16 ) ) ;
2039
1992
let cipher = file . slice ( 16 ) ;
2040
- let keyIv = await deriveKeyIv ( mainPassword . value , pbkdf2salt ) ;
1993
+ //let keyIv = await deriveKeyIv(mainPassword.value, pbkdf2salt);
1994
+ let keyIv = await deriveKeyIv ( mainPassword , pbkdf2salt ) ;
2041
1995
//console.log ( "pbkdf2salt: " + btoa(String.fromCharCode.apply(null, pbkdf2salt)) );
2042
1996
//log.textContent += "\r\npbkdf2salt: " + btoa(String.fromCharCode.apply(null, pbkdf2salt));
2043
1997
//log.textContent += "\r\nstarting to decrypt ...";
0 commit comments