const crypto = require('crypto');
// Function to generate a signature for a given data and secret key
function generateSignature(data, secretKey) {
const hmac = crypto.createHmac('sha256', secretKey);
hmac.update(data);
return hmac.digest();
}
// Example session ID
const sessionId = "example_session_id";
// Example secret key (should be securely stored in your application)
const secretKey = Buffer.from("example_secret_key", 'utf-8');
// Data to sign (in this case, just the session ID)
const data = Buffer.from(sessionId, 'utf-8');
// Generate signatures for session and legacy session
const sessionSignature = generateSignature(data, secretKey);
const legacySessionSignature = generateSignature(data, secretKey);
// Encode signatures as base64 strings for use in cookies
const sessionSignatureBase64 = sessionSignature.toString('base64').replace(/=/g, '');
const legacySessionSignatureBase64 = legacySessionSignature.toString('base64').replace(/=/g, '');
// Print the encoded signatures
console.log("Session Signature:", sessionSignatureBase64);
console.log("Legacy Session Signature:", legacySessionSignatureBase64);
Top comments (0)