feat(server): user and server license endpoints (#10682)
* feat: user license endpoints * feat: server license endpoints * chore: pr feedback * chore: add more test cases * chore: add prod license public keys * chore: open-api generation
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { compareSync, hash } from 'bcrypt';
|
||||
import { createHash, randomBytes, randomUUID } from 'node:crypto';
|
||||
import { createHash, createPublicKey, createVerify, randomBytes, randomUUID } from 'node:crypto';
|
||||
import { createReadStream } from 'node:fs';
|
||||
import { ICryptoRepository } from 'src/interfaces/crypto.interface';
|
||||
import { Instrumentation } from 'src/utils/instrumentation';
|
||||
@@ -28,6 +28,21 @@ export class CryptoRepository implements ICryptoRepository {
|
||||
return createHash('sha256').update(value).digest('base64');
|
||||
}
|
||||
|
||||
verifySha256(value: string, encryptedValue: string, publicKey: string) {
|
||||
const publicKeyBuffer = Buffer.from(publicKey, 'base64');
|
||||
const cryptoPublicKey = createPublicKey({
|
||||
key: publicKeyBuffer,
|
||||
type: 'spki',
|
||||
format: 'pem',
|
||||
});
|
||||
|
||||
const verifier = createVerify('SHA256');
|
||||
verifier.update(value);
|
||||
verifier.end();
|
||||
const encryptedValueBuffer = Buffer.from(encryptedValue, 'base64');
|
||||
return verifier.verify(cryptoPublicKey, encryptedValueBuffer);
|
||||
}
|
||||
|
||||
hashSha1(value: string | Buffer): Buffer {
|
||||
return createHash('sha1').update(value).digest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user