En-/decryption fixed
This commit is contained in:
@@ -1,16 +1,18 @@
|
||||
import crypto from 'crypto';
|
||||
|
||||
const algorithm = 'aes-256-ctr';
|
||||
const secretKey = process.env.SECRET_KEY;
|
||||
const algorithm = 'aes-256-ecb'; // Verwende ECB-Modus, der keinen IV benötigt
|
||||
const key = crypto.scryptSync(process.env.SECRET_KEY, 'salt', 32); // Der Schlüssel sollte eine Länge von 32 Bytes haben
|
||||
|
||||
export const encrypt = (text) => {
|
||||
const cipher = crypto.createCipheriv(algorithm, secretKey, Buffer.alloc(16, 0));
|
||||
const encrypted = Buffer.concat([cipher.update(text), cipher.final()]);
|
||||
return encrypted.toString('hex');
|
||||
const cipher = crypto.createCipheriv(algorithm, key, null); // Kein IV verwendet
|
||||
let encrypted = cipher.update(text, 'utf8', 'hex');
|
||||
encrypted += cipher.final('hex');
|
||||
return encrypted;
|
||||
};
|
||||
|
||||
export const decrypt = (hash) => {
|
||||
const decipher = crypto.createDecipheriv(algorithm, secretKey, Buffer.alloc(16, 0));
|
||||
const decrpyted = Buffer.concat([decipher.update(Buffer.from(hash, 'hex')), decipher.final()]);
|
||||
return decrpyted.toString();
|
||||
export const decrypt = (text) => {
|
||||
const decipher = crypto.createDecipheriv(algorithm, key, null); // Kein IV verwendet
|
||||
let decrypted = decipher.update(text, 'hex', 'utf8');
|
||||
decrypted += decipher.final('utf8');
|
||||
return decrypted;
|
||||
};
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
import crypto from 'crypto';
|
||||
|
||||
const algorithm = 'aes-256-cbc';
|
||||
const secretKey = process.env.SECRET_KEY;
|
||||
const algorithm = 'aes-256-ecb';
|
||||
const key = crypto.scryptSync(process.env.SECRET_KEY, 'salt', 32);
|
||||
|
||||
export const generateIv = () => {
|
||||
return crypto.randomBytes(16);
|
||||
};
|
||||
|
||||
export const encrypt = (text, iv) => {
|
||||
const cipher = crypto.createCipheriv(algorithm, Buffer.from(secretKey, 'utf-8'), iv);
|
||||
export const encrypt = (text) => {
|
||||
const cipher = crypto.createCipheriv(algorithm, key, null);
|
||||
let encrypted = cipher.update(text, 'utf8', 'hex');
|
||||
encrypted += cipher.final('hex');
|
||||
return encrypted;
|
||||
};
|
||||
|
||||
export const decrypt = (text, iv) => {
|
||||
const decipher = crypto.createDecipheriv(algorithm, Buffer.from(secretKey, 'utf-8'), iv);
|
||||
export const decrypt = (text) => {
|
||||
const decipher = crypto.createDecipheriv(algorithm, key, null);
|
||||
let decrypted = decipher.update(text, 'hex', 'utf8');
|
||||
decrypted += decipher.final('utf8');
|
||||
return decrypted;
|
||||
|
||||
@@ -35,8 +35,8 @@ const initializeTypes = async () => {
|
||||
sexualpreference: { type: 'singleselect', 'setting': 'sexuality', minAge: 14 },
|
||||
gender: { type: 'singleselect', setting: 'personal' },
|
||||
pubichair: { type: 'singleselect', setting: 'sexuality', minAge: 14 },
|
||||
penislenght: { type: 'int', setting: 'sexuality', minAge: 14, gender: 'm' },
|
||||
brasize: { type: 'string', setting: 'sexuality', minAge: 14, gender: 'f' }
|
||||
penislenght: { type: 'int', setting: 'sexuality', minAge: 14, gender: 'male' },
|
||||
brasize: { type: 'string', setting: 'sexuality', minAge: 14, gender: 'female' }
|
||||
};
|
||||
Object.keys(userParams).forEach(async(key) => {
|
||||
const item = userParams[key];
|
||||
@@ -56,6 +56,8 @@ const initializeTypes = async () => {
|
||||
hairlength: ['short', 'medium', 'long', 'bald', 'other'],
|
||||
skincolor: ['light', 'medium', 'dark', 'other'],
|
||||
freckles: ['much', 'medium', 'less', 'none'],
|
||||
sexualpreference: ['straight', 'gay', 'bi', 'pan', 'asexual'],
|
||||
pubichair: ['none', 'short', 'medium', 'long', 'hairy', 'waxed', 'landingstrip', 'bikinizone', 'other'],
|
||||
};
|
||||
Object.keys(valuesList).forEach(async(key) => {
|
||||
const values = valuesList[key];
|
||||
|
||||
10
backend/utils/userdata.js
Normal file
10
backend/utils/userdata.js
Normal file
@@ -0,0 +1,10 @@
|
||||
export const calculateAge = (birthdate) => {
|
||||
const today = new Date();
|
||||
const birthDate = new Date(birthdate);
|
||||
let age = today.getFullYear() - birthDate.getFullYear();
|
||||
const monthDiff = today.getMonth() - birthDate.getMonth();
|
||||
if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDate.getDate())) {
|
||||
age--;
|
||||
}
|
||||
return age;
|
||||
};
|
||||
Reference in New Issue
Block a user