fix: imports and SecureByteContext in node
This commit is contained in:
parent
76b2a284d5
commit
6e02559f4e
2 changed files with 8 additions and 6 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -7,4 +7,6 @@ coverage/
|
||||||
.nyc_output/
|
.nyc_output/
|
||||||
build/
|
build/
|
||||||
*.node
|
*.node
|
||||||
settings.json
|
settings.json
|
||||||
|
*.pem
|
||||||
|
client_keys/
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
* Matches the Python implementation using RSA-OAEP with SHA-256
|
* Matches the Python implementation using RSA-OAEP with SHA-256
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { getCrypto, pemToArrayBuffer, arrayBufferToPem, stringToArrayBuffer, arrayBufferToString } from './utils';
|
import { getCrypto, pemToArrayBuffer, arrayBufferToPem, stringToArrayBuffer, arrayBufferToString, generateRandomBytes } from './utils';
|
||||||
import { SecureByteContext } from '../memory/secure';
|
import { SecureByteContext } from '../memory/secure';
|
||||||
|
|
||||||
export class RSAOperations {
|
export class RSAOperations {
|
||||||
|
|
@ -162,8 +162,8 @@ export class RSAOperations {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Wrap salt so it is zeroed after use
|
// Wrap salt so it is zeroed after use
|
||||||
const saltBytes = crypto.getRandomValues(new Uint8Array(16));
|
const saltBytes = generateRandomBytes(16);
|
||||||
const saltContext = new SecureByteContext(saltBytes.buffer, true);
|
const saltContext = new SecureByteContext(saltBytes.buffer as ArrayBuffer, true);
|
||||||
return saltContext.use(async (saltBuf) => {
|
return saltContext.use(async (saltBuf) => {
|
||||||
const saltView = new Uint8Array(saltBuf);
|
const saltView = new Uint8Array(saltBuf);
|
||||||
const derivedKey = await this.subtle.deriveKey(
|
const derivedKey = await this.subtle.deriveKey(
|
||||||
|
|
@ -175,8 +175,8 @@ export class RSAOperations {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Wrap IV so it is zeroed after use
|
// Wrap IV so it is zeroed after use
|
||||||
const ivBytes = crypto.getRandomValues(new Uint8Array(16));
|
const ivBytes = generateRandomBytes(16);
|
||||||
const ivContext = new SecureByteContext(ivBytes.buffer, true);
|
const ivContext = new SecureByteContext(ivBytes.buffer as ArrayBuffer, true);
|
||||||
return ivContext.use(async (ivBuf) => {
|
return ivContext.use(async (ivBuf) => {
|
||||||
const ivView = new Uint8Array(ivBuf);
|
const ivView = new Uint8Array(ivBuf);
|
||||||
const encrypted = await this.subtle.encrypt(
|
const encrypted = await this.subtle.encrypt(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue