Signed-off-by: ale <ale@manalejandro.com>
Este commit está contenido en:
ale
2025-12-08 21:06:35 +01:00
padre ad7a1cf0a7
commit 8fa586731a
Se han modificado 13 ficheros con 18 adiciones y 65 borrados

Ver fichero

@@ -46,9 +46,6 @@ export const INDEX_MAPPING = {
sha512: {
type: 'keyword' as const
},
bcrypt: {
type: 'keyword' as const
},
created_at: {
type: 'date' as const
}

Ver fichero

@@ -1,5 +1,4 @@
import crypto from 'crypto';
import bcrypt from 'bcrypt';
export interface HashResult {
plaintext: string;
@@ -7,22 +6,18 @@ export interface HashResult {
sha1: string;
sha256: string;
sha512: string;
bcrypt: string;
}
/**
* Generate all common hashes for a given plaintext
*/
export async function generateHashes(plaintext: string): Promise<HashResult> {
const bcryptHash = await bcrypt.hash(plaintext, 10);
export function generateHashes(plaintext: string): HashResult {
return {
plaintext,
md5: crypto.createHash('md5').update(plaintext).digest('hex'),
sha1: crypto.createHash('sha1').update(plaintext).digest('hex'),
sha256: crypto.createHash('sha256').update(plaintext).digest('hex'),
sha512: crypto.createHash('sha512').update(plaintext).digest('hex'),
bcrypt: bcryptHash,
};
}
@@ -52,11 +47,6 @@ export function detectHashType(hash: string): string | null {
return 'sha512';
}
// BCrypt: starts with $2a$, $2b$, $2x$, or $2y$
if (/^\$2[abxy]\$/.test(cleanHash)) {
return 'bcrypt';
}
return null;
}
@@ -66,14 +56,3 @@ export function detectHashType(hash: string): string | null {
export function isHash(input: string): boolean {
return detectHashType(input) !== null;
}
/**
* Verify a plaintext against a bcrypt hash
*/
export async function verifyBcrypt(plaintext: string, hash: string): Promise<boolean> {
try {
return await bcrypt.compare(plaintext, hash);
} catch (_error) {
return false;
}
}