-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
99 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import CryptoJS from 'crypto-js' | ||
|
||
export const encryptPassword = (password, secretKey) => { | ||
return CryptoJS.AES.encrypt(password, secretKey).toString() | ||
} | ||
|
||
export const decryptPassword = (encryptedPassword, secretKey) => { | ||
const bytes = CryptoJS.AES.decrypt(encryptedPassword, secretKey) | ||
return bytes.toString(CryptoJS.enc.Utf8) | ||
} | ||
|
||
export const isValidPassword = (encryptedPassword, secretKey, plainPassword) => { | ||
try { | ||
const decryptedPassword = decryptPassword(encryptedPassword, secretKey) | ||
return decryptedPassword === plainPassword | ||
} catch (error) { | ||
console.error('Decryption failed:', error) | ||
return false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
let secretKey = null | ||
|
||
export const initializeSecretKey = async () => { | ||
try { | ||
secretKey = await window.secureApi.getSecretKey() | ||
console.log('Secret key initialized') | ||
} catch (error) { | ||
console.error('Failed to initialize secret key:', error) | ||
throw error | ||
} | ||
} | ||
|
||
export const getSecretKey = () => { | ||
if (!secretKey) { | ||
throw new Error('Secret key has not been initialized') | ||
} | ||
return secretKey | ||
} |