Fix KDF algorithm

This commit is contained in:
Franck Royer 2021-10-19 11:26:09 +11:00
parent 501d9d50d4
commit 5cbc4b90fb
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
5 changed files with 36 additions and 3 deletions

Binary file not shown.

View File

@ -25,6 +25,7 @@
"devDependencies": {
"@types/chai": "^4.2.22",
"@types/mocha": "^9.0.0",
"@types/pbkdf2": "^3.1.0",
"@types/secp256k1": "^4.0.3",
"@typescript-eslint/eslint-plugin": "^4.31.1",
"@typescript-eslint/parser": "^4.31.1",
@ -47,6 +48,7 @@
"ecies-geth": "^1.5.3",
"js-sha3": "^0.8.0",
"js-waku": "^0.13.1",
"pbkdf2": "^3.1.2",
"protobufjs": "^6.11.2",
"secp256k1": "^4.0.2"
}

View File

@ -0,0 +1,14 @@
import { expect } from "chai";
import { createSymKeyFromPassword } from "./encryption";
describe("Encryption", () => {
it("Generate symmetric key from password", async function () {
const str = "arbitrary data here";
const symKey = await createSymKeyFromPassword(str);
expect(Buffer.from(symKey).toString("hex")).to.eq(
"c49ad65ebf2a7b7253bf400e3d27719362a91b2c9b9f54d50a69117021666c33"
);
});
});

View File

@ -1,9 +1,15 @@
import { kdf } from "ecies-geth";
import pbkdf2 from "pbkdf2";
const AESKeyLength = 32; // bytes
export async function createSymKeyFromPassword(
password: string
): Promise<Uint8Array> {
return kdf(Buffer.from(password, "utf-8"), AESKeyLength);
return pbkdf2.pbkdf2Sync(
Buffer.from(password, "utf-8"),
"",
65356,
AESKeyLength,
"sha256"
);
}

View File

@ -938,6 +938,15 @@ __metadata:
languageName: node
linkType: hard
"@types/pbkdf2@npm:^3.1.0":
version: 3.1.0
resolution: "@types/pbkdf2@npm:3.1.0"
dependencies:
"@types/node": "*"
checksum: d15024b1957c21cf3b8887329d9bd8dfde754cf13a09d76ae25f1391cfc62bb8b8d7b760773c5dbaa748172fba8b3e0c3dbe962af6ccbd69b76df12a48dfba40
languageName: node
linkType: hard
"@types/prettier@npm:^1.19.0":
version: 1.19.1
resolution: "@types/prettier@npm:1.19.1"
@ -8755,7 +8764,7 @@ fsevents@~2.3.2:
languageName: node
linkType: hard
"pbkdf2@npm:^3.0.3":
"pbkdf2@npm:^3.0.3, pbkdf2@npm:^3.1.2":
version: 3.1.2
resolution: "pbkdf2@npm:3.1.2"
dependencies:
@ -10487,6 +10496,7 @@ resolve@^2.0.0-next.3:
dependencies:
"@types/chai": ^4.2.22
"@types/mocha": ^9.0.0
"@types/pbkdf2": ^3.1.0
"@types/secp256k1": ^4.0.3
"@typescript-eslint/eslint-plugin": ^4.31.1
"@typescript-eslint/parser": ^4.31.1
@ -10503,6 +10513,7 @@ resolve@^2.0.0-next.3:
js-waku: ^0.13.1
mocha: ^9.1.1
npm-run-all: ^4.1.5
pbkdf2: ^3.1.2
prettier: ^2.4.0
protobufjs: ^6.11.2
secp256k1: ^4.0.2