decrypt notes
This commit is contained in:
15
src/utils/crypto.ts
Normal file
15
src/utils/crypto.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import CryptoJS from 'crypto-js'
|
||||
|
||||
const encryptionPrefix = 'contexted|'
|
||||
const salt = 'salt'
|
||||
|
||||
export const calculateClientKey = (passphrase: string): ClientKey => {
|
||||
return CryptoJS.PBKDF2(passphrase, salt, { keySize: 256 / 32 }).toString()
|
||||
}
|
||||
|
||||
export const decrypt = (encryptedMessage: string, key: string): string => {
|
||||
const decryptedMessage = CryptoJS.AES.decrypt(encryptedMessage, key).toString(CryptoJS.enc.Utf8)
|
||||
if (!decryptedMessage.startsWith(encryptionPrefix))
|
||||
throw new Error("Message doesn't have valid encryption")
|
||||
return decryptedMessage.substring(encryptionPrefix.length)
|
||||
}
|
||||
@@ -5,8 +5,7 @@ export const formatDate = (date: Date | number): string => {
|
||||
? new Date(date)
|
||||
: date
|
||||
const dateDistanceInWords = formatDistance(dateToFormat, new Date()) + ' ago'
|
||||
|
||||
return isToday(date) ? dateDistanceInWords : format(date, 'D MMMM [at] HH:mm ')
|
||||
return isToday(date) ? dateDistanceInWords : format(date, 'd MMMM \'at\' HH:mm ')
|
||||
}
|
||||
|
||||
export const getAllMatches = (regex: RegExp, input: string): RegExpExecArray[] => {
|
||||
|
||||
Reference in New Issue
Block a user