Skip to content

Commit

Permalink
change encoding cipher algorithms
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-meilan committed Jan 10, 2024
1 parent 80c9244 commit 455cb86
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/utils/security.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ export const encrypt = (value: string, key: string = ''): EncryptedData => {
encryptor.end();

const cipher = encryptor.read().toString('base64');
return { cipher, iv: iv.toString('base64') };
return { cipher, iv: iv.toString('hex') };
};

export const decrypt = (value: string, iv: string = '', key: string = '') => {
if (!key || !iv) return value;

const hashedKey = hashFrom(key);
const decrypter = createDecipheriv(ENCRYPTION_ALGORITHM, hashedKey, Buffer.from(iv, 'base64'));
const decrypter = createDecipheriv(ENCRYPTION_ALGORITHM, hashedKey, Buffer.from(iv, 'hex'));

decrypter.write(Buffer.from(value, 'base64'));
decrypter.end();
Expand Down Expand Up @@ -93,15 +93,15 @@ export const obtainBiometrics = (title?: string | null, cancel?: string | null)
export const getStoredPassword = () => EncryptedStorage.getItem(StorageKeys.PASSWORD);

export const storePassword = async (password: string) => {
const hashedPassword = hashFrom(password, 'sha512').toString('base64');
const hashedPassword = hashFrom(password).toString('hex');

await EncryptedStorage.setItem(StorageKeys.PASSWORD, hashedPassword);
};

export const comparePassword = async (password: string) => {
const storedPassword = await getStoredPassword();

const hashedPassword = hashFrom(password, 'sha512').toString('base64');
const hashedPassword = hashFrom(password).toString('hex');

return storedPassword === hashedPassword;
};

0 comments on commit 455cb86

Please sign in to comment.