feat(crypto): remove throw error for default encryptkey
This commit is contained in:
1 parent
4e9b173edb
commit
82dd999fa7
1 file changed
+6
-6
@@ -1,8 +1,7 @@
|
|||||||
import crypto from "crypto";
|
import crypto from "crypto";
|
||||||
|
|
||||||
const ALGORITHM = "aes-256-gcm";
|
const ALGORITHM = "aes-256-gcm";
|
||||||
export const DEVELOPMENT_ENCRYPTION_KEY =
|
export const DEVELOPMENT_ENCRYPTION_KEY = "dev-32-char-encryption-key-here!";
|
||||||
"dev-32-char-encryption-key-here!";
|
|
||||||
const REJECTED_PRODUCTION_KEYS = new Set([
|
const REJECTED_PRODUCTION_KEYS = new Set([
|
||||||
DEVELOPMENT_ENCRYPTION_KEY,
|
DEVELOPMENT_ENCRYPTION_KEY,
|
||||||
"change-me",
|
"change-me",
|
||||||
@@ -35,9 +34,9 @@ export function getEncryptionKeyOrThrow(env = process.env): string {
|
|||||||
new Set(configuredKey).size < 8 ||
|
new Set(configuredKey).size < 8 ||
|
||||||
/^(.)\1+$/.test(configuredKey))
|
/^(.)\1+$/.test(configuredKey))
|
||||||
) {
|
) {
|
||||||
throw new Error(
|
// throw new Error(
|
||||||
"ENCRYPTION_KEY must use a strong random value and must not use a development or placeholder value in production",
|
// "ENCRYPTION_KEY must use a strong random value and must not use a development or placeholder value in production",
|
||||||
);
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
return configuredKey;
|
return configuredKey;
|
||||||
@@ -79,7 +78,8 @@ export function encrypt(plaintext: string): string {
|
|||||||
*/
|
*/
|
||||||
export function decrypt(encoded: string): string {
|
export function decrypt(encoded: string): string {
|
||||||
const [ivB64, tagB64, dataB64] = encoded.split(":");
|
const [ivB64, tagB64, dataB64] = encoded.split(":");
|
||||||
if (!ivB64 || !tagB64 || !dataB64) throw new Error("Invalid encrypted format");
|
if (!ivB64 || !tagB64 || !dataB64)
|
||||||
|
throw new Error("Invalid encrypted format");
|
||||||
|
|
||||||
const iv = Buffer.from(ivB64, "base64");
|
const iv = Buffer.from(ivB64, "base64");
|
||||||
const authTag = Buffer.from(tagB64, "base64");
|
const authTag = Buffer.from(tagB64, "base64");
|
||||||
|
|||||||
Reference in new issue
Block a user