configure salt rotation period using env vars. Closed #3427
This commit is contained in:
1 parent
5267222a67
commit
e21c1c83bb
2 files changed
+13
-3
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import crypto from 'node:crypto';
|
||||
import { startOfDay, startOfMonth, startOfWeek } from 'date-fns';
|
||||
import { v4, v5, v7 } from 'uuid';
|
||||
|
||||
const ALGORITHM = 'aes-256-gcm';
|
||||
@@ -67,3 +68,11 @@ export function uuid(...args: any) {
|
||||
export function createAuthKey() {
|
||||
return crypto.randomBytes(16).toString('hex');
|
||||
}
|
||||
|
||||
export function getSalt(saltRotation: string, createdAt: Date): string {
|
||||
return hash(
|
||||
(saltRotation === 'day' ? startOfDay : saltRotation === 'week' ? startOfWeek : startOfMonth)(
|
||||
createdAt,
|
||||
).toUTCString(),
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user