@abdellatif.dev/cryptjs
Version:
A JavaScript/TypeScript library that brings cryptographic functionality from Dart to the web
16 lines (15 loc) • 473 B
JavaScript
;
import { randomBytes } from "crypto";
export const maxSaltLength = 16;
export function genSalt(len = maxSaltLength) {
return randomBytes(len).toString("hex");
}
export default function validateSalt(salt) {
if (salt === void 0) return genSalt();
if (salt.includes("$")) {
throw new Error("Salt contains '$' character");
}
if (salt.length > maxSaltLength) return salt.substring(0, maxSaltLength);
return salt;
}
//# sourceMappingURL=salt.js.map