Skip to content

Commit

Permalink
Remove getKeyFromPassphrase() in favour of using fish128()
Browse files Browse the repository at this point in the history
  • Loading branch information
fishylunar committed Aug 3, 2023
1 parent ff1a13c commit 501a24c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ describe("generic", () => {
.toMatchObject({ filename: 'index.test.js', extension: '.js', directoryPath: '.' });
});
test("string to hex hash", () => {
expect(shark.cryptography.getKeyFromPassphrase("hello world").toString("hex"))
.toBe("f3399f2597c239c53bb3ac36a611ad558ae61aea3a20736455179d4390050482");
expect(shark.cryptography.hash.fish128("hello world", "utf8").toString("hex"))
.toBe("7a3405bfd4fc5750e747480dcd60510a35a92bbb489b041eb5c70a891f2fc634");
});
});
describe("fish hash", () => {
Expand Down
13 changes: 2 additions & 11 deletions src/🐟/cryptography.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,6 @@ class Cryptography {
};
}

/**
* Generates a pbkdf2 (sha512) hash based on the given string
* @param {string} passphrase
* @returns {string}
*/
static getKeyFromPassphrase(passphrase) {
return crypto.pbkdf2Sync(passphrase, 'salt', 100000, 32, 'sha512');
}

/**
* Given features[] and "file path or string" returns computed ID string
* @param {string[]} features Array of strings, taken from args, containing info about what info we use to create the ID string for encryption
Expand Down Expand Up @@ -537,7 +528,7 @@ class Cryptography {
const jsonString = JSON.stringify(obj); // Stringify the object

// Parses the given passphrase into a pbkdf2 (sha512) hash
const parsedKey = Cryptography.getKeyFromPassphrase(passphrase);
const parsedKey = Cryptography.hash.fish128(passphrase, "utf8");

// Create the cipher and encrypt the data
const iv = Buffer.from(Cryptography.hash.fish64(parsedKey, "utf8", true), 'utf8');
Expand All @@ -560,7 +551,7 @@ class Cryptography {
*/
static decryptObject(passphrase, data) {
// Parse provided passphrase
const parsedKey = Cryptography.getKeyFromPassphrase(passphrase);
const parsedKey = Cryptography.hash.fish128(passphrase, "utf8");

// Define encryptedString as the input parameter id, and unobfuscate it
let encryptedString = data;
Expand Down

0 comments on commit 501a24c

Please sign in to comment.