-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
34 lines (23 loc) · 808 Bytes
/
index.js
File metadata and controls
34 lines (23 loc) · 808 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use strict'
const PORT = 8050
const app = require('express')()
const cors = require('cors')
const crypto = require('crypto')
app.use(cors())
app.get('/encrypt/:key/:text?', (req, res) => {
const key =req.params.key
const text = req.params.text || req.params.key
const cipher = crypto.createCipher('aes-256-ctr', key)
let encrypted = cipher.update(decodeURIComponent(text), 'utf8', 'hex')
encrypted += cipher.final('hex')
res.send(encrypted)
})
app.get('/decrypt/:key/:text?', (req, res) => {
const decipher = crypto.createDecipher('aes-256-ctr', req.params.key)
let decrypted = decipher.update(req.params.text, 'hex', 'utf8')
decrypted += decipher.final('utf8')
res.send(decrypted)
})
app.listen(PORT, () => {
console.log(`* Server listening on port ${PORT}...`)
})