Skip to content

Commit

Permalink
Merge pull request #72 from PeculiarVentures:develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
microshine authored Mar 29, 2024
2 parents e95c128 + 650a3cb commit b7ed67b
Show file tree
Hide file tree
Showing 4 changed files with 373 additions and 358 deletions.
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,24 @@
"devDependencies": {
"@peculiar/webcrypto-test": "^1.0.7",
"@types/mocha": "^10.0.6",
"@types/node": "^20.11.4",
"@typescript-eslint/eslint-plugin": "^6.19.0",
"@typescript-eslint/parser": "^6.19.0",
"eslint": "^8.56.0",
"@types/node": "^20.11.30",
"@typescript-eslint/eslint-plugin": "^7.4.0",
"@typescript-eslint/parser": "^7.4.0",
"eslint": "^8.57.0",
"eslint-plugin-import": "^2.29.1",
"mocha": "^10.2.0",
"mocha": "^10.4.0",
"rimraf": "^5.0.5",
"rollup": "^4.9.5",
"rollup": "^4.13.2",
"rollup-plugin-typescript2": "^0.36.0",
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
"typescript": "^5.4.3"
},
"dependencies": {
"@peculiar/asn1-schema": "^2.3.8",
"@peculiar/json-schema": "^1.1.12",
"pvtsutils": "^1.3.5",
"tslib": "^2.6.2",
"webcrypto-core": "^1.7.8"
"webcrypto-core": "^1.7.9"
},
"nyc": {
"extension": [
Expand Down
10 changes: 6 additions & 4 deletions src/mechs/aes/crypto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Buffer } from "buffer";
import crypto, { CipherGCM, DecipherGCM } from "crypto";
import crypto, { CipherGCMTypes } from "crypto";
import { JsonParser, JsonSerializer } from "@peculiar/json-schema";
import * as core from "webcrypto-core";
import { AesCryptoKey } from "./key";
Expand Down Expand Up @@ -136,9 +136,9 @@ export class AesCrypto {
}

public static async encryptAesGCM(algorithm: AesGcmParams, key: AesCryptoKey, data: Buffer) {
const cipher = crypto.createCipheriv(`aes-${key.algorithm.length}-gcm`, key.data, Buffer.from(algorithm.iv as ArrayBuffer), {
const cipher = crypto.createCipheriv(`aes-${key.algorithm.length}-gcm` as CipherGCMTypes, key.data, Buffer.from(algorithm.iv as ArrayBuffer), {
authTagLength: (algorithm.tagLength || 128) >> 3,
} as any) as CipherGCM; // NodeJs d.ts doesn't support CipherGCMOptions for createCipheriv
}); // NodeJs d.ts doesn't support CipherGCMOptions for createCipheriv
if (algorithm.additionalData) {
cipher.setAAD(Buffer.from(algorithm.additionalData as ArrayBuffer));
}
Expand All @@ -149,8 +149,10 @@ export class AesCrypto {
}

public static async decryptAesGCM(algorithm: AesGcmParams, key: AesCryptoKey, data: Buffer) {
const decipher = crypto.createDecipheriv(`aes-${key.algorithm.length}-gcm`, key.data, new Uint8Array(algorithm.iv as ArrayBuffer)) as DecipherGCM;
const tagLength = (algorithm.tagLength || 128) >> 3;
const decipher = crypto.createDecipheriv(`aes-${key.algorithm.length}-gcm` as CipherGCMTypes, key.data, new Uint8Array(algorithm.iv as ArrayBuffer), {
authTagLength: tagLength,
});
const enc = data.slice(0, data.length - tagLength);
const tag = data.slice(data.length - tagLength);
if (algorithm.additionalData) {
Expand Down
1 change: 1 addition & 0 deletions test/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const ciphers = nodeCrypto.getCiphers();

WebcryptoTest.check(crypto as any, {
DESCBC: !ciphers.includes("des-cbc"),
RSAESPKCS1: nodeMajorVersion >= 18,
});
context("Crypto", () => {

Expand Down
Loading

0 comments on commit b7ed67b

Please sign in to comment.