Fix KDF algorithm
This commit is contained in:
parent
501d9d50d4
commit
5cbc4b90fb
Binary file not shown.
|
@ -25,6 +25,7 @@
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/chai": "^4.2.22",
|
"@types/chai": "^4.2.22",
|
||||||
"@types/mocha": "^9.0.0",
|
"@types/mocha": "^9.0.0",
|
||||||
|
"@types/pbkdf2": "^3.1.0",
|
||||||
"@types/secp256k1": "^4.0.3",
|
"@types/secp256k1": "^4.0.3",
|
||||||
"@typescript-eslint/eslint-plugin": "^4.31.1",
|
"@typescript-eslint/eslint-plugin": "^4.31.1",
|
||||||
"@typescript-eslint/parser": "^4.31.1",
|
"@typescript-eslint/parser": "^4.31.1",
|
||||||
|
@ -47,6 +48,7 @@
|
||||||
"ecies-geth": "^1.5.3",
|
"ecies-geth": "^1.5.3",
|
||||||
"js-sha3": "^0.8.0",
|
"js-sha3": "^0.8.0",
|
||||||
"js-waku": "^0.13.1",
|
"js-waku": "^0.13.1",
|
||||||
|
"pbkdf2": "^3.1.2",
|
||||||
"protobufjs": "^6.11.2",
|
"protobufjs": "^6.11.2",
|
||||||
"secp256k1": "^4.0.2"
|
"secp256k1": "^4.0.2"
|
||||||
}
|
}
|
||||||
|
|
|
@ -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"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
|
@ -1,9 +1,15 @@
|
||||||
import { kdf } from "ecies-geth";
|
import pbkdf2 from "pbkdf2";
|
||||||
|
|
||||||
const AESKeyLength = 32; // bytes
|
const AESKeyLength = 32; // bytes
|
||||||
|
|
||||||
export async function createSymKeyFromPassword(
|
export async function createSymKeyFromPassword(
|
||||||
password: string
|
password: string
|
||||||
): Promise<Uint8Array> {
|
): Promise<Uint8Array> {
|
||||||
return kdf(Buffer.from(password, "utf-8"), AESKeyLength);
|
return pbkdf2.pbkdf2Sync(
|
||||||
|
Buffer.from(password, "utf-8"),
|
||||||
|
"",
|
||||||
|
65356,
|
||||||
|
AESKeyLength,
|
||||||
|
"sha256"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
13
yarn.lock
13
yarn.lock
|
@ -938,6 +938,15 @@ __metadata:
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
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":
|
"@types/prettier@npm:^1.19.0":
|
||||||
version: 1.19.1
|
version: 1.19.1
|
||||||
resolution: "@types/prettier@npm:1.19.1"
|
resolution: "@types/prettier@npm:1.19.1"
|
||||||
|
@ -8755,7 +8764,7 @@ fsevents@~2.3.2:
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"pbkdf2@npm:^3.0.3":
|
"pbkdf2@npm:^3.0.3, pbkdf2@npm:^3.1.2":
|
||||||
version: 3.1.2
|
version: 3.1.2
|
||||||
resolution: "pbkdf2@npm:3.1.2"
|
resolution: "pbkdf2@npm:3.1.2"
|
||||||
dependencies:
|
dependencies:
|
||||||
|
@ -10487,6 +10496,7 @@ resolve@^2.0.0-next.3:
|
||||||
dependencies:
|
dependencies:
|
||||||
"@types/chai": ^4.2.22
|
"@types/chai": ^4.2.22
|
||||||
"@types/mocha": ^9.0.0
|
"@types/mocha": ^9.0.0
|
||||||
|
"@types/pbkdf2": ^3.1.0
|
||||||
"@types/secp256k1": ^4.0.3
|
"@types/secp256k1": ^4.0.3
|
||||||
"@typescript-eslint/eslint-plugin": ^4.31.1
|
"@typescript-eslint/eslint-plugin": ^4.31.1
|
||||||
"@typescript-eslint/parser": ^4.31.1
|
"@typescript-eslint/parser": ^4.31.1
|
||||||
|
@ -10503,6 +10513,7 @@ resolve@^2.0.0-next.3:
|
||||||
js-waku: ^0.13.1
|
js-waku: ^0.13.1
|
||||||
mocha: ^9.1.1
|
mocha: ^9.1.1
|
||||||
npm-run-all: ^4.1.5
|
npm-run-all: ^4.1.5
|
||||||
|
pbkdf2: ^3.1.2
|
||||||
prettier: ^2.4.0
|
prettier: ^2.4.0
|
||||||
protobufjs: ^6.11.2
|
protobufjs: ^6.11.2
|
||||||
secp256k1: ^4.0.2
|
secp256k1: ^4.0.2
|
||||||
|
|
Loading…
Reference in New Issue