Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is this library compatible with Python Fernet library? #25

Open
nikolovk opened this issue Jan 21, 2023 · 1 comment
Open

Is this library compatible with Python Fernet library? #25

nikolovk opened this issue Jan 21, 2023 · 1 comment

Comments

@nikolovk
Copy link

Could we decrypt messages that are encrypted with https://cryptography.io/en/latest/fernet/?

@albertpurnama
Copy link

albertpurnama commented Apr 30, 2024

Yes this is possible.

// Get the encryption key from the environment variable or use a default value
const encryptionKey = process.env.DOCUMENT_ENCRYPTION_KEY || "";

// Create a Fernet cipher using the encryption key
const fernetSecret = new Secret(encryptionKey);

// Decryption function
function decrypt(encryptedText: string): string {
  const token = new Token({
    secret: fernetSecret,
    token: encryptedText,
    ttl: 0,
  });
  return token.decode();
}

Usage:

const encryptedText =
    "gAAAAABmIAROED2UWje1er9CmTjN8frlusIXk-_tLftujD2J8DexIeXWdfph3S0WOlmbE2HddT-hWN7FwInWuw3aqzj6GvxKY4U0FzMdBVwTh3P4kmTZ1rguPAtnvvlmPOkzUcKsygdL4Ur6oia_ibsbBqN1wKfKarbBmckNrtA_a-GbSoBlDE3M3XbvY1cXZj3F2Ii_kTMve_n8FEWxt0pQtAOZelp77I6v44jmQ5iRuStdYhwIWEAtl_cIePCw8j9oMIGSs9JR0bGU31h3ZaeYDSUhQpKtWvpGw_L8SGwlbbYA_FM7GZZ7X5jWpt98GTbQTBM5wNAyuG5ZZ_MCVZhJXUCaZTpw463NzR60C-1As0vKKuiKiqOj8tN1N15gOH1TNrdNmDY5X6PeaJ3eh1iqP2pC_Voer1k2Fe-yAlSNXDaaXHkWctY=";

const decryptedText = decrypt(encryptedText);
console.log(decryptedText);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants