MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / encrypt

Function encrypt

examples/encrypted_source_url.js:8–23  ·  view source on GitHub ↗
(target, key)

Source from the content-addressed store, hash-verified

6)
7
8const encrypt = (target, key) => {
9 const data = Buffer.from(target).toString('binary');
10
11 // We use a random iv generation, but you'll probably want to use some
12 // deterministic method
13 const iv = crypto.randomBytes(16)
14
15 const cipher = crypto.createCipheriv('aes-256-cbc', key, iv);
16
17 let encrypted = Buffer.from(
18 cipher.update(data, 'utf8', 'binary') + cipher.final('binary'),
19 'binary',
20 );
21
22 return Buffer.concat([iv, encrypted]).toString('base64').replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_')
23}
24
25const url = 'http://img.example.com/pretty/image.jpg'
26const encrypted_url = encrypt(url, KEY)

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected