MCPcopy Index your code
hub / github.com/CapSoftware/Cap / encrypt

Function encrypt

packages/database/crypto.ts:63–96  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

61}
62
63export async function encrypt(text: string): Promise<string> {
64 if (!text) {
65 throw new Error("Cannot encrypt empty or null text");
66 }
67
68 try {
69 const salt = crypto.getRandomValues(new Uint8Array(SALT_LENGTH));
70 const iv = crypto.getRandomValues(new Uint8Array(IV_LENGTH));
71 const key = await deriveKey(salt);
72
73 const encoded = new TextEncoder().encode(text);
74 const encrypted = await crypto.subtle.encrypt(
75 {
76 name: ALGORITHM.name,
77 iv,
78 },
79 key,
80 encoded,
81 );
82
83 const result = Buffer.concat([
84 Buffer.from(salt),
85 Buffer.from(iv),
86 Buffer.from(encrypted),
87 ]);
88
89 return result.toString("base64");
90 } catch (error: unknown) {
91 if (error instanceof Error) {
92 throw new Error(`Encryption failed: ${error.message}`);
93 }
94 throw new Error("Encryption failed");
95 }
96}
97
98export async function decrypt(encryptedText: string): Promise<string> {
99 if (!encryptedText) {

Callers 8

StorageRepoClass · 0.90
saveOrganizationS3ConfigFunction · 0.90
regenerateDeveloperKeysFunction · 0.90
createDeveloperAppFunction · 0.90
storage.tsFile · 0.90
s3Config.tsFile · 0.90

Calls 1

deriveKeyFunction · 0.85

Tested by

no test coverage detected