Skip to content

Commit

Permalink
Create dataPrivacy.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Dec 4, 2024
1 parent 013d2e4 commit 977fbc9
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions src/security/dataPrivacy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// dataPrivacy.js

const crypto = require('crypto');
const fs = require('fs');
const path = require('path');

// Utility function to generate a random string for anonymization
function generateRandomString(length) {
return crypto.randomBytes(length).toString('hex');
}

// Anonymize user data
function anonymizeData(userData) {
return {
...userData,
name: generateRandomString(10),
email: `${generateRandomString(5)}@example.com`,
phone: generateRandomString(10),
};
}

// Store user consent
function storeUser Consent(userId, consent) {
const consentData = {
userId,
consent,
timestamp: new Date().toISOString(),
};
fs.appendFileSync(path.join(__dirname, 'consentLog.json'), JSON.stringify(consentData) + '\n');
}

// Retrieve user consent
function getUser Consent(userId) {
const consentLog = fs.readFileSync(path.join(__dirname, 'consentLog.json'), 'utf-8');
const consentEntries = consentLog.split('\n').filter(Boolean).map(JSON.parse);
return consentEntries.filter(entry => entry.userId === userId);
}

// Handle data access requests
function handleDataAccessRequest(userId) {
// Simulate fetching user data from a database
const userData = {
userId,
name: 'John Doe',
email: '[email protected]',
phone: '1234567890',
};

return {
userData: anonymizeData(userData),
consent: getUser Consent(userId),
};
}

// Exporting functions for use in other modules
module.exports = {
anonymizeData,
storeUser Consent,
getUser Consent,
handleDataAccessRequest,
};

0 comments on commit 977fbc9

Please sign in to comment.