-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add
decrypt()
util to scripts (#3019)
- Loading branch information
1 parent
c57f7a5
commit 4b7d32f
Showing
3 changed files
with
40 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { decrypt } from "@opensystemslab/planx-core"; | ||
|
||
/** | ||
* Decrypt a secret | ||
* Currently used to read secure secrets from the team_integrations table back to plain text | ||
* e.g using API keys in another context, checking values | ||
* | ||
* @param encryptionKey - The encryption key - a 32-byte string | ||
* @param secret - The encrypted secret and initialization vector in the format ${secret}:${iv} | ||
* @returns The decrypted secret | ||
* @example pnpm decrypt <encryptionKey> <secret> | ||
*/ | ||
function main() { | ||
try { | ||
if (process.argv.length < 4) { | ||
console.error("Usage: pnpm decrypt <encryptionKey> <secret>"); | ||
process.exit(1); | ||
} | ||
|
||
const encryptionKey = process.argv[2]; | ||
const secret = process.argv[3]; | ||
const decrypted = decrypt(secret, encryptionKey); | ||
|
||
console.log("Success!"); | ||
console.log(decrypted); | ||
} catch (error) { | ||
console.log("Error!"); | ||
console.error(error); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters