MCPcopy
hub / github.com/CapSoftware/Cap / decrypt

Function decrypt

packages/database/crypto.ts:98–128  ·  view source on GitHub ↗
(encryptedText: string)

Source from the content-addressed store, hash-verified

96}
97
98export async function decrypt(encryptedText: string): Promise<string> {
99 if (!encryptedText) {
100 throw new Error("Cannot decrypt empty or null text");
101 }
102
103 try {
104 const encrypted = Buffer.from(encryptedText, "base64");
105
106 const salt = encrypted.subarray(0, SALT_LENGTH);
107 const iv = encrypted.subarray(SALT_LENGTH, SALT_LENGTH + IV_LENGTH);
108 const content = encrypted.subarray(SALT_LENGTH + IV_LENGTH);
109
110 const key = await deriveKey(salt);
111
112 const decrypted = await crypto.subtle.decrypt(
113 {
114 name: ALGORITHM.name,
115 iv,
116 },
117 key,
118 content,
119 );
120
121 return new TextDecoder().decode(decrypted);
122 } catch (error: unknown) {
123 if (error instanceof Error) {
124 throw new Error(`Decryption failed: ${error.message}`);
125 }
126 throw new Error("Decryption failed");
127 }
128}
129
130const PASSWORD_KEY_LENGTH = 32;
131const PASSWORD_ITERATIONS = 100000;

Callers 11

StorageRepoClass · 0.90
createBucketClientMethod · 0.90
S3BucketsClass · 0.90
decryptS3ConfigFunction · 0.90
parseDriveConfigFunction · 0.90
getS3InputCredentialsFunction · 0.90
parseConfigFunction · 0.90
getDeveloperAppsFunction · 0.90
storage.tsFile · 0.90
decryptBucketConfigFunction · 0.90

Calls 1

deriveKeyFunction · 0.85

Tested by

no test coverage detected